| 1 | /* | 
|---|
| 2 | Unix SMB/CIFS implementation. | 
|---|
| 3 |  | 
|---|
| 4 | dcerpc utility functions | 
|---|
| 5 |  | 
|---|
| 6 | Copyright (C) Andrew Tridgell 2003 | 
|---|
| 7 | Copyright (C) Jelmer Vernooij 2004 | 
|---|
| 8 | Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005 | 
|---|
| 9 | Copyright (C) Rafal Szczesniak 2006 | 
|---|
| 10 |  | 
|---|
| 11 | This program is free software; you can redistribute it and/or modify | 
|---|
| 12 | it under the terms of the GNU General Public License as published by | 
|---|
| 13 | the Free Software Foundation; either version 3 of the License, or | 
|---|
| 14 | (at your option) any later version. | 
|---|
| 15 |  | 
|---|
| 16 | This program is distributed in the hope that it will be useful, | 
|---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | GNU General Public License for more details. | 
|---|
| 20 |  | 
|---|
| 21 | You should have received a copy of the GNU General Public License | 
|---|
| 22 | along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 23 | */ | 
|---|
| 24 |  | 
|---|
| 25 | #include "includes.h" | 
|---|
| 26 | #include "../../lib/util/util_net.h" | 
|---|
| 27 | #include "librpc/gen_ndr/ndr_epmapper.h" | 
|---|
| 28 | #include "librpc/gen_ndr/ndr_misc.h" | 
|---|
| 29 | #include "librpc/rpc/dcerpc.h" | 
|---|
| 30 | #include "rpc_common.h" | 
|---|
| 31 |  | 
|---|
| 32 | #undef strcasecmp | 
|---|
| 33 | #undef strncasecmp | 
|---|
| 34 |  | 
|---|
| 35 | #define MAX_PROTSEQ             10 | 
|---|
| 36 |  | 
|---|
| 37 | static const struct { | 
|---|
| 38 | const char *name; | 
|---|
| 39 | enum dcerpc_transport_t transport; | 
|---|
| 40 | int num_protocols; | 
|---|
| 41 | enum epm_protocol protseq[MAX_PROTSEQ]; | 
|---|
| 42 | } transports[] = { | 
|---|
| 43 | { "ncacn_np",     NCACN_NP, 3, | 
|---|
| 44 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_SMB, EPM_PROTOCOL_NETBIOS }}, | 
|---|
| 45 | { "ncacn_ip_tcp", NCACN_IP_TCP, 3, | 
|---|
| 46 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_TCP, EPM_PROTOCOL_IP } }, | 
|---|
| 47 | { "ncacn_http", NCACN_HTTP, 3, | 
|---|
| 48 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_HTTP, EPM_PROTOCOL_IP } }, | 
|---|
| 49 | { "ncadg_ip_udp", NCACN_IP_UDP, 3, | 
|---|
| 50 | { EPM_PROTOCOL_NCADG, EPM_PROTOCOL_UDP, EPM_PROTOCOL_IP } }, | 
|---|
| 51 | { "ncalrpc", NCALRPC, 2, | 
|---|
| 52 | { EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_NAMED_PIPE } }, | 
|---|
| 53 | { "ncacn_unix_stream", NCACN_UNIX_STREAM, 2, | 
|---|
| 54 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_UNIX_DS } }, | 
|---|
| 55 | { "ncadg_unix_dgram", NCADG_UNIX_DGRAM, 2, | 
|---|
| 56 | { EPM_PROTOCOL_NCADG, EPM_PROTOCOL_UNIX_DS } }, | 
|---|
| 57 | { "ncacn_at_dsp", NCACN_AT_DSP, 3, | 
|---|
| 58 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_APPLETALK, EPM_PROTOCOL_DSP } }, | 
|---|
| 59 | { "ncadg_at_ddp", NCADG_AT_DDP, 3, | 
|---|
| 60 | { EPM_PROTOCOL_NCADG, EPM_PROTOCOL_APPLETALK, EPM_PROTOCOL_DDP } }, | 
|---|
| 61 | { "ncacn_vns_ssp", NCACN_VNS_SPP, 3, | 
|---|
| 62 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_STREETTALK, EPM_PROTOCOL_VINES_SPP } }, | 
|---|
| 63 | { "ncacn_vns_ipc", NCACN_VNS_IPC, 3, | 
|---|
| 64 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_STREETTALK, EPM_PROTOCOL_VINES_IPC }, }, | 
|---|
| 65 | { "ncadg_ipx", NCADG_IPX, 2, | 
|---|
| 66 | { EPM_PROTOCOL_NCADG, EPM_PROTOCOL_IPX }, | 
|---|
| 67 | }, | 
|---|
| 68 | { "ncacn_spx", NCACN_SPX, 3, | 
|---|
| 69 | /* I guess some MS programmer confused the identifier for | 
|---|
| 70 | * EPM_PROTOCOL_UUID (0x0D or 13) with the one for | 
|---|
| 71 | * EPM_PROTOCOL_SPX (0x13) here. -- jelmer*/ | 
|---|
| 72 | { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_UUID }, | 
|---|
| 73 | }, | 
|---|
| 74 | }; | 
|---|
| 75 |  | 
|---|
| 76 | static const struct { | 
|---|
| 77 | const char *name; | 
|---|
| 78 | uint32_t flag; | 
|---|
| 79 | } ncacn_options[] = { | 
|---|
| 80 | {"sign", DCERPC_SIGN}, | 
|---|
| 81 | {"seal", DCERPC_SEAL}, | 
|---|
| 82 | {"connect", DCERPC_CONNECT}, | 
|---|
| 83 | {"spnego", DCERPC_AUTH_SPNEGO}, | 
|---|
| 84 | {"ntlm", DCERPC_AUTH_NTLM}, | 
|---|
| 85 | {"krb5", DCERPC_AUTH_KRB5}, | 
|---|
| 86 | {"validate", DCERPC_DEBUG_VALIDATE_BOTH}, | 
|---|
| 87 | {"print", DCERPC_DEBUG_PRINT_BOTH}, | 
|---|
| 88 | {"padcheck", DCERPC_DEBUG_PAD_CHECK}, | 
|---|
| 89 | {"bigendian", DCERPC_PUSH_BIGENDIAN}, | 
|---|
| 90 | {"smb2", DCERPC_SMB2}, | 
|---|
| 91 | {"hdrsign", DCERPC_HEADER_SIGNING}, | 
|---|
| 92 | {"ndr64", DCERPC_NDR64}, | 
|---|
| 93 | {"localaddress", DCERPC_LOCALADDRESS} | 
|---|
| 94 | }; | 
|---|
| 95 |  | 
|---|
| 96 | const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor) | 
|---|
| 97 | { | 
|---|
| 98 | struct ndr_syntax_id syntax; | 
|---|
| 99 | NTSTATUS status; | 
|---|
| 100 |  | 
|---|
| 101 | switch(epm_floor->lhs.protocol) { | 
|---|
| 102 | case EPM_PROTOCOL_UUID: | 
|---|
| 103 | status = dcerpc_floor_get_lhs_data(epm_floor, &syntax); | 
|---|
| 104 | if (NT_STATUS_IS_OK(status)) { | 
|---|
| 105 | /* lhs is used: UUID */ | 
|---|
| 106 | char *uuidstr; | 
|---|
| 107 |  | 
|---|
| 108 | if (GUID_equal(&syntax.uuid, &ndr_transfer_syntax.uuid)) { | 
|---|
| 109 | return "NDR"; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | if (GUID_equal(&syntax.uuid, &ndr64_transfer_syntax.uuid)) { | 
|---|
| 113 | return "NDR64"; | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | uuidstr = GUID_string(mem_ctx, &syntax.uuid); | 
|---|
| 117 |  | 
|---|
| 118 | return talloc_asprintf(mem_ctx, " uuid %s/0x%02x", uuidstr, syntax.if_version); | 
|---|
| 119 | } else { /* IPX */ | 
|---|
| 120 | return talloc_asprintf(mem_ctx, "IPX:%s", | 
|---|
| 121 | data_blob_hex_string_upper(mem_ctx, &epm_floor->rhs.uuid.unknown)); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | case EPM_PROTOCOL_NCACN: | 
|---|
| 125 | return "RPC-C"; | 
|---|
| 126 |  | 
|---|
| 127 | case EPM_PROTOCOL_NCADG: | 
|---|
| 128 | return "RPC"; | 
|---|
| 129 |  | 
|---|
| 130 | case EPM_PROTOCOL_NCALRPC: | 
|---|
| 131 | return "NCALRPC"; | 
|---|
| 132 |  | 
|---|
| 133 | case EPM_PROTOCOL_DNET_NSP: | 
|---|
| 134 | return "DNET/NSP"; | 
|---|
| 135 |  | 
|---|
| 136 | case EPM_PROTOCOL_IP: | 
|---|
| 137 | return talloc_asprintf(mem_ctx, "IP:%s", epm_floor->rhs.ip.ipaddr); | 
|---|
| 138 |  | 
|---|
| 139 | case EPM_PROTOCOL_NAMED_PIPE: | 
|---|
| 140 | return talloc_asprintf(mem_ctx, "NAMED-PIPE:%s", epm_floor->rhs.named_pipe.path); | 
|---|
| 141 |  | 
|---|
| 142 | case EPM_PROTOCOL_SMB: | 
|---|
| 143 | return talloc_asprintf(mem_ctx, "SMB:%s", epm_floor->rhs.smb.unc); | 
|---|
| 144 |  | 
|---|
| 145 | case EPM_PROTOCOL_UNIX_DS: | 
|---|
| 146 | return talloc_asprintf(mem_ctx, "Unix:%s", epm_floor->rhs.unix_ds.path); | 
|---|
| 147 |  | 
|---|
| 148 | case EPM_PROTOCOL_NETBIOS: | 
|---|
| 149 | return talloc_asprintf(mem_ctx, "NetBIOS:%s", epm_floor->rhs.netbios.name); | 
|---|
| 150 |  | 
|---|
| 151 | case EPM_PROTOCOL_NETBEUI: | 
|---|
| 152 | return "NETBeui"; | 
|---|
| 153 |  | 
|---|
| 154 | case EPM_PROTOCOL_SPX: | 
|---|
| 155 | return "SPX"; | 
|---|
| 156 |  | 
|---|
| 157 | case EPM_PROTOCOL_NB_IPX: | 
|---|
| 158 | return "NB_IPX"; | 
|---|
| 159 |  | 
|---|
| 160 | case EPM_PROTOCOL_HTTP: | 
|---|
| 161 | return talloc_asprintf(mem_ctx, "HTTP:%d", epm_floor->rhs.http.port); | 
|---|
| 162 |  | 
|---|
| 163 | case EPM_PROTOCOL_TCP: | 
|---|
| 164 | return talloc_asprintf(mem_ctx, "TCP:%d", epm_floor->rhs.tcp.port); | 
|---|
| 165 |  | 
|---|
| 166 | case EPM_PROTOCOL_UDP: | 
|---|
| 167 | return talloc_asprintf(mem_ctx, "UDP:%d", epm_floor->rhs.udp.port); | 
|---|
| 168 |  | 
|---|
| 169 | default: | 
|---|
| 170 | return talloc_asprintf(mem_ctx, "UNK(%02x):", epm_floor->lhs.protocol); | 
|---|
| 171 | } | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 |  | 
|---|
| 175 | /* | 
|---|
| 176 | form a binding string from a binding structure | 
|---|
| 177 | */ | 
|---|
| 178 | _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b) | 
|---|
| 179 | { | 
|---|
| 180 | char *s = talloc_strdup(mem_ctx, ""); | 
|---|
| 181 | int i; | 
|---|
| 182 | const char *t_name = NULL; | 
|---|
| 183 |  | 
|---|
| 184 | if (b->transport != NCA_UNKNOWN) { | 
|---|
| 185 | t_name = derpc_transport_string_by_transport(b->transport); | 
|---|
| 186 | if (!t_name) { | 
|---|
| 187 | return NULL; | 
|---|
| 188 | } | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | if (!GUID_all_zero(&b->object.uuid)) { | 
|---|
| 192 | s = talloc_asprintf(s, "%s@", | 
|---|
| 193 | GUID_string(mem_ctx, &b->object.uuid)); | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | if (t_name != NULL) { | 
|---|
| 197 | s = talloc_asprintf_append_buffer(s, "%s:", t_name); | 
|---|
| 198 | if (s == NULL) { | 
|---|
| 199 | return NULL; | 
|---|
| 200 | } | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | if (b->host) { | 
|---|
| 204 | s = talloc_asprintf_append_buffer(s, "%s", b->host); | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | if (!b->endpoint && !b->options && !b->flags) { | 
|---|
| 208 | return s; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | s = talloc_asprintf_append_buffer(s, "["); | 
|---|
| 212 |  | 
|---|
| 213 | if (b->endpoint) { | 
|---|
| 214 | s = talloc_asprintf_append_buffer(s, "%s", b->endpoint); | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | /* this is a *really* inefficent way of dealing with strings, | 
|---|
| 218 | but this is rarely called and the strings are always short, | 
|---|
| 219 | so I don't care */ | 
|---|
| 220 | for (i=0;b->options && b->options[i];i++) { | 
|---|
| 221 | s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]); | 
|---|
| 222 | if (!s) return NULL; | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | for (i=0;i<ARRAY_SIZE(ncacn_options);i++) { | 
|---|
| 226 | if (b->flags & ncacn_options[i].flag) { | 
|---|
| 227 | if (ncacn_options[i].flag == DCERPC_LOCALADDRESS && b->localaddress) { | 
|---|
| 228 | s = talloc_asprintf_append_buffer(s, ",%s=%s", ncacn_options[i].name, | 
|---|
| 229 | b->localaddress); | 
|---|
| 230 | } else { | 
|---|
| 231 | s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); | 
|---|
| 232 | } | 
|---|
| 233 | if (!s) return NULL; | 
|---|
| 234 | } | 
|---|
| 235 | } | 
|---|
| 236 |  | 
|---|
| 237 | s = talloc_asprintf_append_buffer(s, "]"); | 
|---|
| 238 |  | 
|---|
| 239 | return s; | 
|---|
| 240 | } | 
|---|
| 241 |  | 
|---|
| 242 | /* | 
|---|
| 243 | parse a binding string into a dcerpc_binding structure | 
|---|
| 244 | */ | 
|---|
| 245 | _PUBLIC_ NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out) | 
|---|
| 246 | { | 
|---|
| 247 | struct dcerpc_binding *b; | 
|---|
| 248 | char *options; | 
|---|
| 249 | char *p; | 
|---|
| 250 | int i, j, comma_count; | 
|---|
| 251 |  | 
|---|
| 252 | b = talloc_zero(mem_ctx, struct dcerpc_binding); | 
|---|
| 253 | if (!b) { | 
|---|
| 254 | return NT_STATUS_NO_MEMORY; | 
|---|
| 255 | } | 
|---|
| 256 |  | 
|---|
| 257 | p = strchr(s, '@'); | 
|---|
| 258 |  | 
|---|
| 259 | if (p && PTR_DIFF(p, s) == 36) { /* 36 is the length of a UUID */ | 
|---|
| 260 | NTSTATUS status; | 
|---|
| 261 | DATA_BLOB blob = data_blob(s, 36); | 
|---|
| 262 | status = GUID_from_data_blob(&blob, &b->object.uuid); | 
|---|
| 263 |  | 
|---|
| 264 | if (NT_STATUS_IS_ERR(status)) { | 
|---|
| 265 | DEBUG(0, ("Failed parsing UUID\n")); | 
|---|
| 266 | return status; | 
|---|
| 267 | } | 
|---|
| 268 |  | 
|---|
| 269 | s = p + 1; | 
|---|
| 270 | } else { | 
|---|
| 271 | ZERO_STRUCT(b->object); | 
|---|
| 272 | } | 
|---|
| 273 |  | 
|---|
| 274 | b->object.if_version = 0; | 
|---|
| 275 |  | 
|---|
| 276 | p = strchr(s, ':'); | 
|---|
| 277 |  | 
|---|
| 278 | if (p == NULL) { | 
|---|
| 279 | b->transport = NCA_UNKNOWN; | 
|---|
| 280 | } else { | 
|---|
| 281 | char *type = talloc_strndup(mem_ctx, s, PTR_DIFF(p, s)); | 
|---|
| 282 | if (!type) { | 
|---|
| 283 | return NT_STATUS_NO_MEMORY; | 
|---|
| 284 | } | 
|---|
| 285 |  | 
|---|
| 286 | for (i=0;i<ARRAY_SIZE(transports);i++) { | 
|---|
| 287 | if (strcasecmp(type, transports[i].name) == 0) { | 
|---|
| 288 | b->transport = transports[i].transport; | 
|---|
| 289 | break; | 
|---|
| 290 | } | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | if (i==ARRAY_SIZE(transports)) { | 
|---|
| 294 | DEBUG(0,("Unknown dcerpc transport '%s'\n", type)); | 
|---|
| 295 | return NT_STATUS_INVALID_PARAMETER; | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | talloc_free(type); | 
|---|
| 299 |  | 
|---|
| 300 | s = p+1; | 
|---|
| 301 | } | 
|---|
| 302 |  | 
|---|
| 303 | p = strchr(s, '['); | 
|---|
| 304 | if (p) { | 
|---|
| 305 | b->host = talloc_strndup(b, s, PTR_DIFF(p, s)); | 
|---|
| 306 | options = talloc_strdup(mem_ctx, p+1); | 
|---|
| 307 | if (options[strlen(options)-1] != ']') { | 
|---|
| 308 | return NT_STATUS_INVALID_PARAMETER; | 
|---|
| 309 | } | 
|---|
| 310 | options[strlen(options)-1] = 0; | 
|---|
| 311 | } else { | 
|---|
| 312 | b->host = talloc_strdup(b, s); | 
|---|
| 313 | options = NULL; | 
|---|
| 314 | } | 
|---|
| 315 | if (!b->host) { | 
|---|
| 316 | return NT_STATUS_NO_MEMORY; | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | b->target_hostname = b->host; | 
|---|
| 320 |  | 
|---|
| 321 | b->options = NULL; | 
|---|
| 322 | b->flags = 0; | 
|---|
| 323 | b->assoc_group_id = 0; | 
|---|
| 324 | b->endpoint = NULL; | 
|---|
| 325 | b->localaddress = NULL; | 
|---|
| 326 |  | 
|---|
| 327 | if (!options) { | 
|---|
| 328 | *b_out = b; | 
|---|
| 329 | return NT_STATUS_OK; | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | comma_count = count_chars(options, ','); | 
|---|
| 333 |  | 
|---|
| 334 | b->options = talloc_array(b, const char *, comma_count+2); | 
|---|
| 335 | if (!b->options) { | 
|---|
| 336 | return NT_STATUS_NO_MEMORY; | 
|---|
| 337 | } | 
|---|
| 338 |  | 
|---|
| 339 | for (i=0; (p = strchr(options, ',')); i++) { | 
|---|
| 340 | b->options[i] = talloc_strndup(b, options, PTR_DIFF(p, options)); | 
|---|
| 341 | if (!b->options[i]) { | 
|---|
| 342 | return NT_STATUS_NO_MEMORY; | 
|---|
| 343 | } | 
|---|
| 344 | options = p+1; | 
|---|
| 345 | } | 
|---|
| 346 | b->options[i] = options; | 
|---|
| 347 | b->options[i+1] = NULL; | 
|---|
| 348 |  | 
|---|
| 349 | /* some options are pre-parsed for convenience */ | 
|---|
| 350 | for (i=0;b->options[i];i++) { | 
|---|
| 351 | for (j=0;j<ARRAY_SIZE(ncacn_options);j++) { | 
|---|
| 352 | size_t opt_len = strlen(ncacn_options[j].name); | 
|---|
| 353 | if (strncasecmp(ncacn_options[j].name, b->options[i], opt_len) == 0) { | 
|---|
| 354 | int k; | 
|---|
| 355 | char c = b->options[i][opt_len]; | 
|---|
| 356 |  | 
|---|
| 357 | if (ncacn_options[j].flag == DCERPC_LOCALADDRESS && c == '=') { | 
|---|
| 358 | b->localaddress = talloc_strdup(b, &b->options[i][opt_len+1]); | 
|---|
| 359 | } else if (c != 0) { | 
|---|
| 360 | continue; | 
|---|
| 361 | } | 
|---|
| 362 |  | 
|---|
| 363 | b->flags |= ncacn_options[j].flag; | 
|---|
| 364 | for (k=i;b->options[k];k++) { | 
|---|
| 365 | b->options[k] = b->options[k+1]; | 
|---|
| 366 | } | 
|---|
| 367 | i--; | 
|---|
| 368 | break; | 
|---|
| 369 | } | 
|---|
| 370 | } | 
|---|
| 371 | } | 
|---|
| 372 |  | 
|---|
| 373 | if (b->options[0]) { | 
|---|
| 374 | /* Endpoint is first option */ | 
|---|
| 375 | b->endpoint = b->options[0]; | 
|---|
| 376 | if (strlen(b->endpoint) == 0) b->endpoint = NULL; | 
|---|
| 377 |  | 
|---|
| 378 | for (i=0;b->options[i];i++) { | 
|---|
| 379 | b->options[i] = b->options[i+1]; | 
|---|
| 380 | } | 
|---|
| 381 | } | 
|---|
| 382 |  | 
|---|
| 383 | if (b->options[0] == NULL) | 
|---|
| 384 | b->options = NULL; | 
|---|
| 385 |  | 
|---|
| 386 | *b_out = b; | 
|---|
| 387 | return NT_STATUS_OK; | 
|---|
| 388 | } | 
|---|
| 389 |  | 
|---|
| 390 | _PUBLIC_ NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, | 
|---|
| 391 | struct ndr_syntax_id *syntax) | 
|---|
| 392 | { | 
|---|
| 393 | TALLOC_CTX *mem_ctx = talloc_init("floor_get_lhs_data"); | 
|---|
| 394 | struct ndr_pull *ndr; | 
|---|
| 395 | enum ndr_err_code ndr_err; | 
|---|
| 396 | uint16_t if_version=0; | 
|---|
| 397 |  | 
|---|
| 398 | ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx); | 
|---|
| 399 | if (ndr == NULL) { | 
|---|
| 400 | talloc_free(mem_ctx); | 
|---|
| 401 | return NT_STATUS_NO_MEMORY; | 
|---|
| 402 | } | 
|---|
| 403 | ndr->flags |= LIBNDR_FLAG_NOALIGN; | 
|---|
| 404 |  | 
|---|
| 405 | ndr_err = ndr_pull_GUID(ndr, NDR_SCALARS | NDR_BUFFERS, &syntax->uuid); | 
|---|
| 406 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { | 
|---|
| 407 | talloc_free(mem_ctx); | 
|---|
| 408 | return ndr_map_error2ntstatus(ndr_err); | 
|---|
| 409 | } | 
|---|
| 410 |  | 
|---|
| 411 | ndr_err = ndr_pull_uint16(ndr, NDR_SCALARS, &if_version); | 
|---|
| 412 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { | 
|---|
| 413 | talloc_free(mem_ctx); | 
|---|
| 414 | return ndr_map_error2ntstatus(ndr_err); | 
|---|
| 415 | } | 
|---|
| 416 |  | 
|---|
| 417 | syntax->if_version = if_version; | 
|---|
| 418 |  | 
|---|
| 419 | talloc_free(mem_ctx); | 
|---|
| 420 |  | 
|---|
| 421 | return NT_STATUS_OK; | 
|---|
| 422 | } | 
|---|
| 423 |  | 
|---|
| 424 | static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax) | 
|---|
| 425 | { | 
|---|
| 426 | DATA_BLOB blob; | 
|---|
| 427 | struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx); | 
|---|
| 428 |  | 
|---|
| 429 | ndr->flags |= LIBNDR_FLAG_NOALIGN; | 
|---|
| 430 |  | 
|---|
| 431 | ndr_push_GUID(ndr, NDR_SCALARS | NDR_BUFFERS, &syntax->uuid); | 
|---|
| 432 | ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version); | 
|---|
| 433 |  | 
|---|
| 434 | blob = ndr_push_blob(ndr); | 
|---|
| 435 | talloc_steal(mem_ctx, blob.data); | 
|---|
| 436 | talloc_free(ndr); | 
|---|
| 437 | return blob; | 
|---|
| 438 | } | 
|---|
| 439 |  | 
|---|
| 440 | static bool dcerpc_floor_pack_rhs_if_version_data( | 
|---|
| 441 | TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax, | 
|---|
| 442 | DATA_BLOB *pblob) | 
|---|
| 443 | { | 
|---|
| 444 | DATA_BLOB blob; | 
|---|
| 445 | struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx); | 
|---|
| 446 | enum ndr_err_code ndr_err; | 
|---|
| 447 |  | 
|---|
| 448 | if (ndr == NULL) { | 
|---|
| 449 | return false; | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 | ndr->flags |= LIBNDR_FLAG_NOALIGN; | 
|---|
| 453 |  | 
|---|
| 454 | ndr_err = ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version >> 16); | 
|---|
| 455 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { | 
|---|
| 456 | return false; | 
|---|
| 457 | } | 
|---|
| 458 |  | 
|---|
| 459 | blob = ndr_push_blob(ndr); | 
|---|
| 460 | talloc_steal(mem_ctx, blob.data); | 
|---|
| 461 | talloc_free(ndr); | 
|---|
| 462 | *pblob = blob; | 
|---|
| 463 | return true; | 
|---|
| 464 | } | 
|---|
| 465 |  | 
|---|
| 466 | const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor) | 
|---|
| 467 | { | 
|---|
| 468 | switch (epm_floor->lhs.protocol) { | 
|---|
| 469 | case EPM_PROTOCOL_TCP: | 
|---|
| 470 | if (epm_floor->rhs.tcp.port == 0) return NULL; | 
|---|
| 471 | return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.tcp.port); | 
|---|
| 472 |  | 
|---|
| 473 | case EPM_PROTOCOL_UDP: | 
|---|
| 474 | if (epm_floor->rhs.udp.port == 0) return NULL; | 
|---|
| 475 | return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.udp.port); | 
|---|
| 476 |  | 
|---|
| 477 | case EPM_PROTOCOL_HTTP: | 
|---|
| 478 | if (epm_floor->rhs.http.port == 0) return NULL; | 
|---|
| 479 | return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.http.port); | 
|---|
| 480 |  | 
|---|
| 481 | case EPM_PROTOCOL_IP: | 
|---|
| 482 | return talloc_strdup(mem_ctx, epm_floor->rhs.ip.ipaddr); | 
|---|
| 483 |  | 
|---|
| 484 | case EPM_PROTOCOL_NCACN: | 
|---|
| 485 | return NULL; | 
|---|
| 486 |  | 
|---|
| 487 | case EPM_PROTOCOL_NCADG: | 
|---|
| 488 | return NULL; | 
|---|
| 489 |  | 
|---|
| 490 | case EPM_PROTOCOL_SMB: | 
|---|
| 491 | if (strlen(epm_floor->rhs.smb.unc) == 0) return NULL; | 
|---|
| 492 | return talloc_strdup(mem_ctx, epm_floor->rhs.smb.unc); | 
|---|
| 493 |  | 
|---|
| 494 | case EPM_PROTOCOL_NAMED_PIPE: | 
|---|
| 495 | if (strlen(epm_floor->rhs.named_pipe.path) == 0) return NULL; | 
|---|
| 496 | return talloc_strdup(mem_ctx, epm_floor->rhs.named_pipe.path); | 
|---|
| 497 |  | 
|---|
| 498 | case EPM_PROTOCOL_NETBIOS: | 
|---|
| 499 | if (strlen(epm_floor->rhs.netbios.name) == 0) return NULL; | 
|---|
| 500 | return talloc_strdup(mem_ctx, epm_floor->rhs.netbios.name); | 
|---|
| 501 |  | 
|---|
| 502 | case EPM_PROTOCOL_NCALRPC: | 
|---|
| 503 | return NULL; | 
|---|
| 504 |  | 
|---|
| 505 | case EPM_PROTOCOL_VINES_SPP: | 
|---|
| 506 | return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.vines_spp.port); | 
|---|
| 507 |  | 
|---|
| 508 | case EPM_PROTOCOL_VINES_IPC: | 
|---|
| 509 | return talloc_asprintf(mem_ctx, "%d", epm_floor->rhs.vines_ipc.port); | 
|---|
| 510 |  | 
|---|
| 511 | case EPM_PROTOCOL_STREETTALK: | 
|---|
| 512 | return talloc_strdup(mem_ctx, epm_floor->rhs.streettalk.streettalk); | 
|---|
| 513 |  | 
|---|
| 514 | case EPM_PROTOCOL_UNIX_DS: | 
|---|
| 515 | if (strlen(epm_floor->rhs.unix_ds.path) == 0) return NULL; | 
|---|
| 516 | return talloc_strdup(mem_ctx, epm_floor->rhs.unix_ds.path); | 
|---|
| 517 |  | 
|---|
| 518 | case EPM_PROTOCOL_NULL: | 
|---|
| 519 | return NULL; | 
|---|
| 520 |  | 
|---|
| 521 | default: | 
|---|
| 522 | DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor->lhs.protocol)); | 
|---|
| 523 | break; | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 | return NULL; | 
|---|
| 527 | } | 
|---|
| 528 |  | 
|---|
| 529 | static NTSTATUS dcerpc_floor_set_rhs_data(TALLOC_CTX *mem_ctx, | 
|---|
| 530 | struct epm_floor *epm_floor, | 
|---|
| 531 | const char *data) | 
|---|
| 532 | { | 
|---|
| 533 | switch (epm_floor->lhs.protocol) { | 
|---|
| 534 | case EPM_PROTOCOL_TCP: | 
|---|
| 535 | epm_floor->rhs.tcp.port = atoi(data); | 
|---|
| 536 | return NT_STATUS_OK; | 
|---|
| 537 |  | 
|---|
| 538 | case EPM_PROTOCOL_UDP: | 
|---|
| 539 | epm_floor->rhs.udp.port = atoi(data); | 
|---|
| 540 | return NT_STATUS_OK; | 
|---|
| 541 |  | 
|---|
| 542 | case EPM_PROTOCOL_HTTP: | 
|---|
| 543 | epm_floor->rhs.http.port = atoi(data); | 
|---|
| 544 | return NT_STATUS_OK; | 
|---|
| 545 |  | 
|---|
| 546 | case EPM_PROTOCOL_IP: | 
|---|
| 547 | epm_floor->rhs.ip.ipaddr = talloc_strdup(mem_ctx, data); | 
|---|
| 548 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.ip.ipaddr); | 
|---|
| 549 | return NT_STATUS_OK; | 
|---|
| 550 |  | 
|---|
| 551 | case EPM_PROTOCOL_NCACN: | 
|---|
| 552 | epm_floor->rhs.ncacn.minor_version = 0; | 
|---|
| 553 | return NT_STATUS_OK; | 
|---|
| 554 |  | 
|---|
| 555 | case EPM_PROTOCOL_NCADG: | 
|---|
| 556 | epm_floor->rhs.ncadg.minor_version = 0; | 
|---|
| 557 | return NT_STATUS_OK; | 
|---|
| 558 |  | 
|---|
| 559 | case EPM_PROTOCOL_SMB: | 
|---|
| 560 | epm_floor->rhs.smb.unc = talloc_strdup(mem_ctx, data); | 
|---|
| 561 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.smb.unc); | 
|---|
| 562 | return NT_STATUS_OK; | 
|---|
| 563 |  | 
|---|
| 564 | case EPM_PROTOCOL_NAMED_PIPE: | 
|---|
| 565 | epm_floor->rhs.named_pipe.path = talloc_strdup(mem_ctx, data); | 
|---|
| 566 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.named_pipe.path); | 
|---|
| 567 | return NT_STATUS_OK; | 
|---|
| 568 |  | 
|---|
| 569 | case EPM_PROTOCOL_NETBIOS: | 
|---|
| 570 | epm_floor->rhs.netbios.name = talloc_strdup(mem_ctx, data); | 
|---|
| 571 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.netbios.name); | 
|---|
| 572 | return NT_STATUS_OK; | 
|---|
| 573 |  | 
|---|
| 574 | case EPM_PROTOCOL_NCALRPC: | 
|---|
| 575 | return NT_STATUS_OK; | 
|---|
| 576 |  | 
|---|
| 577 | case EPM_PROTOCOL_VINES_SPP: | 
|---|
| 578 | epm_floor->rhs.vines_spp.port = atoi(data); | 
|---|
| 579 | return NT_STATUS_OK; | 
|---|
| 580 |  | 
|---|
| 581 | case EPM_PROTOCOL_VINES_IPC: | 
|---|
| 582 | epm_floor->rhs.vines_ipc.port = atoi(data); | 
|---|
| 583 | return NT_STATUS_OK; | 
|---|
| 584 |  | 
|---|
| 585 | case EPM_PROTOCOL_STREETTALK: | 
|---|
| 586 | epm_floor->rhs.streettalk.streettalk = talloc_strdup(mem_ctx, data); | 
|---|
| 587 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.streettalk.streettalk); | 
|---|
| 588 | return NT_STATUS_OK; | 
|---|
| 589 |  | 
|---|
| 590 | case EPM_PROTOCOL_UNIX_DS: | 
|---|
| 591 | epm_floor->rhs.unix_ds.path = talloc_strdup(mem_ctx, data); | 
|---|
| 592 | NT_STATUS_HAVE_NO_MEMORY(epm_floor->rhs.unix_ds.path); | 
|---|
| 593 | return NT_STATUS_OK; | 
|---|
| 594 |  | 
|---|
| 595 | case EPM_PROTOCOL_NULL: | 
|---|
| 596 | return NT_STATUS_OK; | 
|---|
| 597 |  | 
|---|
| 598 | default: | 
|---|
| 599 | DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor->lhs.protocol)); | 
|---|
| 600 | break; | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | return NT_STATUS_NOT_SUPPORTED; | 
|---|
| 604 | } | 
|---|
| 605 |  | 
|---|
| 606 | enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot) | 
|---|
| 607 | { | 
|---|
| 608 | int i; | 
|---|
| 609 |  | 
|---|
| 610 | /* Find a transport that has 'prot' as 4th protocol */ | 
|---|
| 611 | for (i=0;i<ARRAY_SIZE(transports);i++) { | 
|---|
| 612 | if (transports[i].num_protocols >= 2 && | 
|---|
| 613 | transports[i].protseq[1] == prot) { | 
|---|
| 614 | return transports[i].transport; | 
|---|
| 615 | } | 
|---|
| 616 | } | 
|---|
| 617 |  | 
|---|
| 618 | /* Unknown transport */ | 
|---|
| 619 | return (unsigned int)-1; | 
|---|
| 620 | } | 
|---|
| 621 |  | 
|---|
| 622 | _PUBLIC_ enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower) | 
|---|
| 623 | { | 
|---|
| 624 | int i; | 
|---|
| 625 |  | 
|---|
| 626 | /* Find a transport that matches this tower */ | 
|---|
| 627 | for (i=0;i<ARRAY_SIZE(transports);i++) { | 
|---|
| 628 | int j; | 
|---|
| 629 | if (transports[i].num_protocols != tower->num_floors - 2) { | 
|---|
| 630 | continue; | 
|---|
| 631 | } | 
|---|
| 632 |  | 
|---|
| 633 | for (j = 0; j < transports[i].num_protocols; j++) { | 
|---|
| 634 | if (transports[i].protseq[j] != tower->floors[j+2].lhs.protocol) { | 
|---|
| 635 | break; | 
|---|
| 636 | } | 
|---|
| 637 | } | 
|---|
| 638 |  | 
|---|
| 639 | if (j == transports[i].num_protocols) { | 
|---|
| 640 | return transports[i].transport; | 
|---|
| 641 | } | 
|---|
| 642 | } | 
|---|
| 643 |  | 
|---|
| 644 | /* Unknown transport */ | 
|---|
| 645 | return (unsigned int)-1; | 
|---|
| 646 | } | 
|---|
| 647 |  | 
|---|
| 648 | _PUBLIC_ const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t) | 
|---|
| 649 | { | 
|---|
| 650 | int i; | 
|---|
| 651 |  | 
|---|
| 652 | for (i=0; i<ARRAY_SIZE(transports); i++) { | 
|---|
| 653 | if (t == transports[i].transport) { | 
|---|
| 654 | return transports[i].name; | 
|---|
| 655 | } | 
|---|
| 656 | } | 
|---|
| 657 | return NULL; | 
|---|
| 658 | } | 
|---|
| 659 |  | 
|---|
| 660 | _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, | 
|---|
| 661 | struct epm_tower *tower, | 
|---|
| 662 | struct dcerpc_binding **b_out) | 
|---|
| 663 | { | 
|---|
| 664 | NTSTATUS status; | 
|---|
| 665 | struct dcerpc_binding *binding; | 
|---|
| 666 |  | 
|---|
| 667 | /* | 
|---|
| 668 | * A tower needs to have at least 4 floors to carry useful | 
|---|
| 669 | * information. Floor 3 is the transport identifier which defines | 
|---|
| 670 | * how many floors are required at least. | 
|---|
| 671 | */ | 
|---|
| 672 | if (tower->num_floors < 4) { | 
|---|
| 673 | return NT_STATUS_INVALID_PARAMETER; | 
|---|
| 674 | } | 
|---|
| 675 |  | 
|---|
| 676 | binding = talloc_zero(mem_ctx, struct dcerpc_binding); | 
|---|
| 677 | NT_STATUS_HAVE_NO_MEMORY(binding); | 
|---|
| 678 |  | 
|---|
| 679 | ZERO_STRUCT(binding->object); | 
|---|
| 680 | binding->options = NULL; | 
|---|
| 681 | binding->host = NULL; | 
|---|
| 682 | binding->target_hostname = NULL; | 
|---|
| 683 | binding->flags = 0; | 
|---|
| 684 | binding->assoc_group_id = 0; | 
|---|
| 685 |  | 
|---|
| 686 | binding->transport = dcerpc_transport_by_tower(tower); | 
|---|
| 687 |  | 
|---|
| 688 | if (binding->transport == (unsigned int)-1) { | 
|---|
| 689 | return NT_STATUS_NOT_SUPPORTED; | 
|---|
| 690 | } | 
|---|
| 691 |  | 
|---|
| 692 | /* Set object uuid */ | 
|---|
| 693 | status = dcerpc_floor_get_lhs_data(&tower->floors[0], &binding->object); | 
|---|
| 694 |  | 
|---|
| 695 | if (!NT_STATUS_IS_OK(status)) { | 
|---|
| 696 | DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status))); | 
|---|
| 697 | return status; | 
|---|
| 698 | } | 
|---|
| 699 |  | 
|---|
| 700 | /* Ignore floor 1, it contains the NDR version info */ | 
|---|
| 701 |  | 
|---|
| 702 | binding->options = NULL; | 
|---|
| 703 |  | 
|---|
| 704 | /* Set endpoint */ | 
|---|
| 705 | if (tower->num_floors >= 4) { | 
|---|
| 706 | binding->endpoint = dcerpc_floor_get_rhs_data(binding, &tower->floors[3]); | 
|---|
| 707 | } else { | 
|---|
| 708 | binding->endpoint = NULL; | 
|---|
| 709 | } | 
|---|
| 710 |  | 
|---|
| 711 | /* Set network address */ | 
|---|
| 712 | if (tower->num_floors >= 5) { | 
|---|
| 713 | binding->host = dcerpc_floor_get_rhs_data(binding, &tower->floors[4]); | 
|---|
| 714 | NT_STATUS_HAVE_NO_MEMORY(binding->host); | 
|---|
| 715 | binding->target_hostname = binding->host; | 
|---|
| 716 | } | 
|---|
| 717 | *b_out = binding; | 
|---|
| 718 | return NT_STATUS_OK; | 
|---|
| 719 | } | 
|---|
| 720 |  | 
|---|
| 721 | _PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx, | 
|---|
| 722 | const struct dcerpc_binding *b) | 
|---|
| 723 | { | 
|---|
| 724 | struct dcerpc_binding *n; | 
|---|
| 725 | uint32_t count; | 
|---|
| 726 |  | 
|---|
| 727 | n = talloc_zero(mem_ctx, struct dcerpc_binding); | 
|---|
| 728 | if (n == NULL) { | 
|---|
| 729 | return NULL; | 
|---|
| 730 | } | 
|---|
| 731 |  | 
|---|
| 732 | n->transport = b->transport; | 
|---|
| 733 | n->object = b->object; | 
|---|
| 734 | n->flags = b->flags; | 
|---|
| 735 | n->assoc_group_id = b->assoc_group_id; | 
|---|
| 736 |  | 
|---|
| 737 | if (b->host != NULL) { | 
|---|
| 738 | n->host = talloc_strdup(n, b->host); | 
|---|
| 739 | if (n->host == NULL) { | 
|---|
| 740 | talloc_free(n); | 
|---|
| 741 | return NULL; | 
|---|
| 742 | } | 
|---|
| 743 | } | 
|---|
| 744 |  | 
|---|
| 745 | if (b->target_hostname != NULL) { | 
|---|
| 746 | n->target_hostname = talloc_strdup(n, b->target_hostname); | 
|---|
| 747 | if (n->target_hostname == NULL) { | 
|---|
| 748 | talloc_free(n); | 
|---|
| 749 | return NULL; | 
|---|
| 750 | } | 
|---|
| 751 | } | 
|---|
| 752 |  | 
|---|
| 753 | if (b->target_principal != NULL) { | 
|---|
| 754 | n->target_principal = talloc_strdup(n, b->target_principal); | 
|---|
| 755 | if (n->target_principal == NULL) { | 
|---|
| 756 | talloc_free(n); | 
|---|
| 757 | return NULL; | 
|---|
| 758 | } | 
|---|
| 759 | } | 
|---|
| 760 |  | 
|---|
| 761 | if (b->localaddress != NULL) { | 
|---|
| 762 | n->localaddress = talloc_strdup(n, b->localaddress); | 
|---|
| 763 | if (n->localaddress == NULL) { | 
|---|
| 764 | talloc_free(n); | 
|---|
| 765 | return NULL; | 
|---|
| 766 | } | 
|---|
| 767 | } | 
|---|
| 768 |  | 
|---|
| 769 | if (b->endpoint != NULL) { | 
|---|
| 770 | n->endpoint = talloc_strdup(n, b->endpoint); | 
|---|
| 771 | if (n->endpoint == NULL) { | 
|---|
| 772 | talloc_free(n); | 
|---|
| 773 | return NULL; | 
|---|
| 774 | } | 
|---|
| 775 | } | 
|---|
| 776 |  | 
|---|
| 777 | for (count = 0; b->options && b->options[count]; count++); | 
|---|
| 778 |  | 
|---|
| 779 | if (count > 0) { | 
|---|
| 780 | uint32_t i; | 
|---|
| 781 |  | 
|---|
| 782 | n->options = talloc_array(n, const char *, count + 1); | 
|---|
| 783 | if (n->options == NULL) { | 
|---|
| 784 | talloc_free(n); | 
|---|
| 785 | return NULL; | 
|---|
| 786 | } | 
|---|
| 787 |  | 
|---|
| 788 | for (i = 0; i < count; i++) { | 
|---|
| 789 | n->options[i] = talloc_strdup(n->options, b->options[i]); | 
|---|
| 790 | if (n->options[i] == NULL) { | 
|---|
| 791 | talloc_free(n); | 
|---|
| 792 | return NULL; | 
|---|
| 793 | } | 
|---|
| 794 | } | 
|---|
| 795 | n->options[count] = NULL; | 
|---|
| 796 | } | 
|---|
| 797 |  | 
|---|
| 798 | return n; | 
|---|
| 799 | } | 
|---|
| 800 |  | 
|---|
| 801 | _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx, | 
|---|
| 802 | const struct dcerpc_binding *binding, | 
|---|
| 803 | struct epm_tower *tower) | 
|---|
| 804 | { | 
|---|
| 805 | const enum epm_protocol *protseq = NULL; | 
|---|
| 806 | int num_protocols = -1, i; | 
|---|
| 807 | NTSTATUS status; | 
|---|
| 808 |  | 
|---|
| 809 | /* Find transport */ | 
|---|
| 810 | for (i=0;i<ARRAY_SIZE(transports);i++) { | 
|---|
| 811 | if (transports[i].transport == binding->transport) { | 
|---|
| 812 | protseq = transports[i].protseq; | 
|---|
| 813 | num_protocols = transports[i].num_protocols; | 
|---|
| 814 | break; | 
|---|
| 815 | } | 
|---|
| 816 | } | 
|---|
| 817 |  | 
|---|
| 818 | if (num_protocols == -1) { | 
|---|
| 819 | DEBUG(0, ("Unable to find transport with id '%d'\n", binding->transport)); | 
|---|
| 820 | return NT_STATUS_UNSUCCESSFUL; | 
|---|
| 821 | } | 
|---|
| 822 |  | 
|---|
| 823 | tower->num_floors = 2 + num_protocols; | 
|---|
| 824 | tower->floors = talloc_array(mem_ctx, struct epm_floor, tower->num_floors); | 
|---|
| 825 |  | 
|---|
| 826 | /* Floor 0 */ | 
|---|
| 827 | tower->floors[0].lhs.protocol = EPM_PROTOCOL_UUID; | 
|---|
| 828 |  | 
|---|
| 829 | tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, &binding->object); | 
|---|
| 830 |  | 
|---|
| 831 | if (!dcerpc_floor_pack_rhs_if_version_data( | 
|---|
| 832 | tower->floors, &binding->object, | 
|---|
| 833 | &tower->floors[0].rhs.uuid.unknown)) { | 
|---|
| 834 | return NT_STATUS_NO_MEMORY; | 
|---|
| 835 | } | 
|---|
| 836 |  | 
|---|
| 837 | /* Floor 1 */ | 
|---|
| 838 | tower->floors[1].lhs.protocol = EPM_PROTOCOL_UUID; | 
|---|
| 839 |  | 
|---|
| 840 | tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, | 
|---|
| 841 | &ndr_transfer_syntax); | 
|---|
| 842 |  | 
|---|
| 843 | tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(tower->floors, 2); | 
|---|
| 844 |  | 
|---|
| 845 | /* Floor 2 to num_protocols */ | 
|---|
| 846 | for (i = 0; i < num_protocols; i++) { | 
|---|
| 847 | tower->floors[2 + i].lhs.protocol = protseq[i]; | 
|---|
| 848 | tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(tower->floors, NULL, 0); | 
|---|
| 849 | ZERO_STRUCT(tower->floors[2 + i].rhs); | 
|---|
| 850 | dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[2 + i], ""); | 
|---|
| 851 | } | 
|---|
| 852 |  | 
|---|
| 853 | /* The 4th floor contains the endpoint */ | 
|---|
| 854 | if (num_protocols >= 2 && binding->endpoint) { | 
|---|
| 855 | status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[3], binding->endpoint); | 
|---|
| 856 | if (NT_STATUS_IS_ERR(status)) { | 
|---|
| 857 | return status; | 
|---|
| 858 | } | 
|---|
| 859 | } | 
|---|
| 860 |  | 
|---|
| 861 | /* The 5th contains the network address */ | 
|---|
| 862 | if (num_protocols >= 3 && binding->host) { | 
|---|
| 863 | if (is_ipaddress(binding->host) || | 
|---|
| 864 | (binding->host[0] == '\\' && binding->host[1] == '\\')) { | 
|---|
| 865 | status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], | 
|---|
| 866 | binding->host); | 
|---|
| 867 | } else { | 
|---|
| 868 | /* note that we don't attempt to resolve the | 
|---|
| 869 | name here - when we get a hostname here we | 
|---|
| 870 | are in the client code, and want to put in | 
|---|
| 871 | a wildcard all-zeros IP for the server to | 
|---|
| 872 | fill in */ | 
|---|
| 873 | status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], | 
|---|
| 874 | "0.0.0.0"); | 
|---|
| 875 | } | 
|---|
| 876 | if (NT_STATUS_IS_ERR(status)) { | 
|---|
| 877 | return status; | 
|---|
| 878 | } | 
|---|
| 879 | } | 
|---|
| 880 |  | 
|---|
| 881 | return NT_STATUS_OK; | 
|---|
| 882 | } | 
|---|