2 Unix SMB/CIFS implementation.
4 dcerpc utility functions
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
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.
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.
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/>.
26 #include "librpc/gen_ndr/ndr_epmapper.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
28 #include "librpc/rpc/dcerpc.h"
31 #define MAX_PROTSEQ 10
35 enum dcerpc_transport_t transport
;
37 enum epm_protocol protseq
[MAX_PROTSEQ
];
39 { "ncacn_np", NCACN_NP
, 3,
40 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_SMB
, EPM_PROTOCOL_NETBIOS
}},
41 { "ncacn_ip_tcp", NCACN_IP_TCP
, 3,
42 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_TCP
, EPM_PROTOCOL_IP
} },
43 { "ncacn_http", NCACN_HTTP
, 3,
44 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_HTTP
, EPM_PROTOCOL_IP
} },
45 { "ncadg_ip_udp", NCACN_IP_UDP
, 3,
46 { EPM_PROTOCOL_NCADG
, EPM_PROTOCOL_UDP
, EPM_PROTOCOL_IP
} },
47 { "ncalrpc", NCALRPC
, 2,
48 { EPM_PROTOCOL_NCALRPC
, EPM_PROTOCOL_NAMED_PIPE
} },
49 { "ncacn_unix_stream", NCACN_UNIX_STREAM
, 2,
50 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_UNIX_DS
} },
51 { "ncadg_unix_dgram", NCADG_UNIX_DGRAM
, 2,
52 { EPM_PROTOCOL_NCADG
, EPM_PROTOCOL_UNIX_DS
} },
53 { "ncacn_at_dsp", NCACN_AT_DSP
, 3,
54 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_APPLETALK
, EPM_PROTOCOL_DSP
} },
55 { "ncadg_at_ddp", NCADG_AT_DDP
, 3,
56 { EPM_PROTOCOL_NCADG
, EPM_PROTOCOL_APPLETALK
, EPM_PROTOCOL_DDP
} },
57 { "ncacn_vns_ssp", NCACN_VNS_SPP
, 3,
58 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_STREETTALK
, EPM_PROTOCOL_VINES_SPP
} },
59 { "ncacn_vns_ipc", NCACN_VNS_IPC
, 3,
60 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_STREETTALK
, EPM_PROTOCOL_VINES_IPC
}, },
61 { "ncadg_ipx", NCADG_IPX
, 2,
62 { EPM_PROTOCOL_NCADG
, EPM_PROTOCOL_IPX
},
64 { "ncacn_spx", NCACN_SPX
, 3,
65 /* I guess some MS programmer confused the identifier for
66 * EPM_PROTOCOL_UUID (0x0D or 13) with the one for
67 * EPM_PROTOCOL_SPX (0x13) here. -- jelmer*/
68 { EPM_PROTOCOL_NCACN
, EPM_PROTOCOL_NCALRPC
, EPM_PROTOCOL_UUID
},
76 {"sign", DCERPC_SIGN
},
77 {"seal", DCERPC_SEAL
},
78 {"connect", DCERPC_CONNECT
},
79 {"spnego", DCERPC_AUTH_SPNEGO
},
80 {"ntlm", DCERPC_AUTH_NTLM
},
81 {"krb5", DCERPC_AUTH_KRB5
},
82 {"validate", DCERPC_DEBUG_VALIDATE_BOTH
},
83 {"print", DCERPC_DEBUG_PRINT_BOTH
},
84 {"padcheck", DCERPC_DEBUG_PAD_CHECK
},
85 {"bigendian", DCERPC_PUSH_BIGENDIAN
},
86 {"smb2", DCERPC_SMB2
},
87 {"hdrsign", DCERPC_HEADER_SIGNING
},
88 {"ndr64", DCERPC_NDR64
}
91 const char *epm_floor_string(TALLOC_CTX
*mem_ctx
, struct epm_floor
*epm_floor
)
93 struct ndr_syntax_id syntax
;
96 switch(epm_floor
->lhs
.protocol
) {
97 case EPM_PROTOCOL_UUID
:
98 status
= dcerpc_floor_get_lhs_data(epm_floor
, &syntax
);
99 if (NT_STATUS_IS_OK(status
)) {
100 /* lhs is used: UUID */
103 if (GUID_equal(&syntax
.uuid
, &ndr_transfer_syntax
.uuid
)) {
107 if (GUID_equal(&syntax
.uuid
, &ndr64_transfer_syntax
.uuid
)) {
111 uuidstr
= GUID_string(mem_ctx
, &syntax
.uuid
);
113 return talloc_asprintf(mem_ctx
, " uuid %s/0x%02x", uuidstr
, syntax
.if_version
);
115 return talloc_asprintf(mem_ctx
, "IPX:%s",
116 data_blob_hex_string_upper(mem_ctx
, &epm_floor
->rhs
.uuid
.unknown
));
119 case EPM_PROTOCOL_NCACN
:
122 case EPM_PROTOCOL_NCADG
:
125 case EPM_PROTOCOL_NCALRPC
:
128 case EPM_PROTOCOL_DNET_NSP
:
131 case EPM_PROTOCOL_IP
:
132 return talloc_asprintf(mem_ctx
, "IP:%s", epm_floor
->rhs
.ip
.ipaddr
);
134 case EPM_PROTOCOL_NAMED_PIPE
:
135 return talloc_asprintf(mem_ctx
, "NAMED-PIPE:%s", epm_floor
->rhs
.named_pipe
.path
);
137 case EPM_PROTOCOL_SMB
:
138 return talloc_asprintf(mem_ctx
, "SMB:%s", epm_floor
->rhs
.smb
.unc
);
140 case EPM_PROTOCOL_UNIX_DS
:
141 return talloc_asprintf(mem_ctx
, "Unix:%s", epm_floor
->rhs
.unix_ds
.path
);
143 case EPM_PROTOCOL_NETBIOS
:
144 return talloc_asprintf(mem_ctx
, "NetBIOS:%s", epm_floor
->rhs
.netbios
.name
);
146 case EPM_PROTOCOL_NETBEUI
:
149 case EPM_PROTOCOL_SPX
:
152 case EPM_PROTOCOL_NB_IPX
:
155 case EPM_PROTOCOL_HTTP
:
156 return talloc_asprintf(mem_ctx
, "HTTP:%d", epm_floor
->rhs
.http
.port
);
158 case EPM_PROTOCOL_TCP
:
159 return talloc_asprintf(mem_ctx
, "TCP:%d", epm_floor
->rhs
.tcp
.port
);
161 case EPM_PROTOCOL_UDP
:
162 return talloc_asprintf(mem_ctx
, "UDP:%d", epm_floor
->rhs
.udp
.port
);
165 return talloc_asprintf(mem_ctx
, "UNK(%02x):", epm_floor
->lhs
.protocol
);
171 form a binding string from a binding structure
173 _PUBLIC_
char *dcerpc_binding_string(TALLOC_CTX
*mem_ctx
, const struct dcerpc_binding
*b
)
175 char *s
= talloc_strdup(mem_ctx
, "");
177 const char *t_name
= NULL
;
179 if (b
->transport
!= NCA_UNKNOWN
) {
180 t_name
= derpc_transport_string_by_transport(b
->transport
);
186 if (!GUID_all_zero(&b
->object
.uuid
)) {
187 s
= talloc_asprintf(s
, "%s@",
188 GUID_string(mem_ctx
, &b
->object
.uuid
));
191 if (t_name
!= NULL
) {
192 s
= talloc_asprintf_append_buffer(s
, "%s:", t_name
);
199 s
= talloc_asprintf_append_buffer(s
, "%s", b
->host
);
202 if (!b
->endpoint
&& !b
->options
&& !b
->flags
) {
206 s
= talloc_asprintf_append_buffer(s
, "[");
209 s
= talloc_asprintf_append_buffer(s
, "%s", b
->endpoint
);
212 /* this is a *really* inefficent way of dealing with strings,
213 but this is rarely called and the strings are always short,
215 for (i
=0;b
->options
&& b
->options
[i
];i
++) {
216 s
= talloc_asprintf_append_buffer(s
, ",%s", b
->options
[i
]);
220 for (i
=0;i
<ARRAY_SIZE(ncacn_options
);i
++) {
221 if (b
->flags
& ncacn_options
[i
].flag
) {
222 s
= talloc_asprintf_append_buffer(s
, ",%s", ncacn_options
[i
].name
);
227 s
= talloc_asprintf_append_buffer(s
, "]");
233 parse a binding string into a dcerpc_binding structure
235 _PUBLIC_ NTSTATUS
dcerpc_parse_binding(TALLOC_CTX
*mem_ctx
, const char *s
, struct dcerpc_binding
**b_out
)
237 struct dcerpc_binding
*b
;
240 int i
, j
, comma_count
;
242 b
= talloc(mem_ctx
, struct dcerpc_binding
);
244 return NT_STATUS_NO_MEMORY
;
249 if (p
&& PTR_DIFF(p
, s
) == 36) { /* 36 is the length of a UUID */
251 DATA_BLOB blob
= data_blob(s
, 36);
252 status
= GUID_from_data_blob(&blob
, &b
->object
.uuid
);
254 if (NT_STATUS_IS_ERR(status
)) {
255 DEBUG(0, ("Failed parsing UUID\n"));
261 ZERO_STRUCT(b
->object
);
264 b
->object
.if_version
= 0;
269 b
->transport
= NCA_UNKNOWN
;
271 char *type
= talloc_strndup(mem_ctx
, s
, PTR_DIFF(p
, s
));
273 return NT_STATUS_NO_MEMORY
;
276 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
277 if (strcasecmp(type
, transports
[i
].name
) == 0) {
278 b
->transport
= transports
[i
].transport
;
283 if (i
==ARRAY_SIZE(transports
)) {
284 DEBUG(0,("Unknown dcerpc transport '%s'\n", type
));
285 return NT_STATUS_INVALID_PARAMETER
;
295 b
->host
= talloc_strndup(b
, s
, PTR_DIFF(p
, s
));
296 options
= talloc_strdup(mem_ctx
, p
+1);
297 if (options
[strlen(options
)-1] != ']') {
298 return NT_STATUS_INVALID_PARAMETER
;
300 options
[strlen(options
)-1] = 0;
302 b
->host
= talloc_strdup(b
, s
);
306 return NT_STATUS_NO_MEMORY
;
309 b
->target_hostname
= b
->host
;
313 b
->assoc_group_id
= 0;
321 comma_count
= count_chars(options
, ',');
323 b
->options
= talloc_array(b
, const char *, comma_count
+2);
325 return NT_STATUS_NO_MEMORY
;
328 for (i
=0; (p
= strchr(options
, ',')); i
++) {
329 b
->options
[i
] = talloc_strndup(b
, options
, PTR_DIFF(p
, options
));
330 if (!b
->options
[i
]) {
331 return NT_STATUS_NO_MEMORY
;
335 b
->options
[i
] = options
;
336 b
->options
[i
+1] = NULL
;
338 /* some options are pre-parsed for convenience */
339 for (i
=0;b
->options
[i
];i
++) {
340 for (j
=0;j
<ARRAY_SIZE(ncacn_options
);j
++) {
341 if (strcasecmp(ncacn_options
[j
].name
, b
->options
[i
]) == 0) {
343 b
->flags
|= ncacn_options
[j
].flag
;
344 for (k
=i
;b
->options
[k
];k
++) {
345 b
->options
[k
] = b
->options
[k
+1];
354 /* Endpoint is first option */
355 b
->endpoint
= b
->options
[0];
356 if (strlen(b
->endpoint
) == 0) b
->endpoint
= NULL
;
358 for (i
=0;b
->options
[i
];i
++) {
359 b
->options
[i
] = b
->options
[i
+1];
363 if (b
->options
[0] == NULL
)
370 _PUBLIC_ NTSTATUS
dcerpc_floor_get_lhs_data(const struct epm_floor
*epm_floor
,
371 struct ndr_syntax_id
*syntax
)
373 TALLOC_CTX
*mem_ctx
= talloc_init("floor_get_lhs_data");
374 struct ndr_pull
*ndr
;
375 enum ndr_err_code ndr_err
;
376 uint16_t if_version
=0;
378 ndr
= ndr_pull_init_blob(&epm_floor
->lhs
.lhs_data
, mem_ctx
, NULL
);
380 talloc_free(mem_ctx
);
381 return NT_STATUS_NO_MEMORY
;
383 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
385 ndr_err
= ndr_pull_GUID(ndr
, NDR_SCALARS
| NDR_BUFFERS
, &syntax
->uuid
);
386 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
387 talloc_free(mem_ctx
);
388 return ndr_map_error2ntstatus(ndr_err
);
391 ndr_err
= ndr_pull_uint16(ndr
, NDR_SCALARS
, &if_version
);
392 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
393 talloc_free(mem_ctx
);
394 return ndr_map_error2ntstatus(ndr_err
);
397 syntax
->if_version
= if_version
;
399 talloc_free(mem_ctx
);
404 static DATA_BLOB
dcerpc_floor_pack_lhs_data(TALLOC_CTX
*mem_ctx
, const struct ndr_syntax_id
*syntax
)
407 struct ndr_push
*ndr
= ndr_push_init_ctx(mem_ctx
, NULL
);
409 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
411 ndr_push_GUID(ndr
, NDR_SCALARS
| NDR_BUFFERS
, &syntax
->uuid
);
412 ndr_push_uint16(ndr
, NDR_SCALARS
, syntax
->if_version
);
414 blob
= ndr_push_blob(ndr
);
415 talloc_steal(mem_ctx
, blob
.data
);
420 static DATA_BLOB
dcerpc_floor_pack_rhs_if_version_data(TALLOC_CTX
*mem_ctx
, const struct ndr_syntax_id
*syntax
)
423 struct ndr_push
*ndr
= ndr_push_init_ctx(mem_ctx
, NULL
);
425 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
427 ndr_push_uint16(ndr
, NDR_SCALARS
, syntax
->if_version
>> 16);
429 blob
= ndr_push_blob(ndr
);
430 talloc_steal(mem_ctx
, blob
.data
);
435 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX
*mem_ctx
, struct epm_floor
*epm_floor
)
437 switch (epm_floor
->lhs
.protocol
) {
438 case EPM_PROTOCOL_TCP
:
439 if (epm_floor
->rhs
.tcp
.port
== 0) return NULL
;
440 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.tcp
.port
);
442 case EPM_PROTOCOL_UDP
:
443 if (epm_floor
->rhs
.udp
.port
== 0) return NULL
;
444 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.udp
.port
);
446 case EPM_PROTOCOL_HTTP
:
447 if (epm_floor
->rhs
.http
.port
== 0) return NULL
;
448 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.http
.port
);
450 case EPM_PROTOCOL_IP
:
451 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.ip
.ipaddr
);
453 case EPM_PROTOCOL_NCACN
:
456 case EPM_PROTOCOL_NCADG
:
459 case EPM_PROTOCOL_SMB
:
460 if (strlen(epm_floor
->rhs
.smb
.unc
) == 0) return NULL
;
461 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.smb
.unc
);
463 case EPM_PROTOCOL_NAMED_PIPE
:
464 if (strlen(epm_floor
->rhs
.named_pipe
.path
) == 0) return NULL
;
465 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.named_pipe
.path
);
467 case EPM_PROTOCOL_NETBIOS
:
468 if (strlen(epm_floor
->rhs
.netbios
.name
) == 0) return NULL
;
469 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.netbios
.name
);
471 case EPM_PROTOCOL_NCALRPC
:
474 case EPM_PROTOCOL_VINES_SPP
:
475 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.vines_spp
.port
);
477 case EPM_PROTOCOL_VINES_IPC
:
478 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.vines_ipc
.port
);
480 case EPM_PROTOCOL_STREETTALK
:
481 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.streettalk
.streettalk
);
483 case EPM_PROTOCOL_UNIX_DS
:
484 if (strlen(epm_floor
->rhs
.unix_ds
.path
) == 0) return NULL
;
485 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.unix_ds
.path
);
487 case EPM_PROTOCOL_NULL
:
491 DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor
->lhs
.protocol
));
498 static NTSTATUS
dcerpc_floor_set_rhs_data(TALLOC_CTX
*mem_ctx
,
499 struct epm_floor
*epm_floor
,
502 switch (epm_floor
->lhs
.protocol
) {
503 case EPM_PROTOCOL_TCP
:
504 epm_floor
->rhs
.tcp
.port
= atoi(data
);
507 case EPM_PROTOCOL_UDP
:
508 epm_floor
->rhs
.udp
.port
= atoi(data
);
511 case EPM_PROTOCOL_HTTP
:
512 epm_floor
->rhs
.http
.port
= atoi(data
);
515 case EPM_PROTOCOL_IP
:
516 epm_floor
->rhs
.ip
.ipaddr
= talloc_strdup(mem_ctx
, data
);
517 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.ip
.ipaddr
);
520 case EPM_PROTOCOL_NCACN
:
521 epm_floor
->rhs
.ncacn
.minor_version
= 0;
524 case EPM_PROTOCOL_NCADG
:
525 epm_floor
->rhs
.ncadg
.minor_version
= 0;
528 case EPM_PROTOCOL_SMB
:
529 epm_floor
->rhs
.smb
.unc
= talloc_strdup(mem_ctx
, data
);
530 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.smb
.unc
);
533 case EPM_PROTOCOL_NAMED_PIPE
:
534 epm_floor
->rhs
.named_pipe
.path
= talloc_strdup(mem_ctx
, data
);
535 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.named_pipe
.path
);
538 case EPM_PROTOCOL_NETBIOS
:
539 epm_floor
->rhs
.netbios
.name
= talloc_strdup(mem_ctx
, data
);
540 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.netbios
.name
);
543 case EPM_PROTOCOL_NCALRPC
:
546 case EPM_PROTOCOL_VINES_SPP
:
547 epm_floor
->rhs
.vines_spp
.port
= atoi(data
);
550 case EPM_PROTOCOL_VINES_IPC
:
551 epm_floor
->rhs
.vines_ipc
.port
= atoi(data
);
554 case EPM_PROTOCOL_STREETTALK
:
555 epm_floor
->rhs
.streettalk
.streettalk
= talloc_strdup(mem_ctx
, data
);
556 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.streettalk
.streettalk
);
559 case EPM_PROTOCOL_UNIX_DS
:
560 epm_floor
->rhs
.unix_ds
.path
= talloc_strdup(mem_ctx
, data
);
561 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.unix_ds
.path
);
564 case EPM_PROTOCOL_NULL
:
568 DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor
->lhs
.protocol
));
572 return NT_STATUS_NOT_SUPPORTED
;
575 enum dcerpc_transport_t
dcerpc_transport_by_endpoint_protocol(int prot
)
579 /* Find a transport that has 'prot' as 4th protocol */
580 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
581 if (transports
[i
].num_protocols
>= 2 &&
582 transports
[i
].protseq
[1] == prot
) {
583 return transports
[i
].transport
;
587 /* Unknown transport */
588 return (unsigned int)-1;
591 _PUBLIC_
enum dcerpc_transport_t
dcerpc_transport_by_tower(const struct epm_tower
*tower
)
595 /* Find a transport that matches this tower */
596 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
598 if (transports
[i
].num_protocols
!= tower
->num_floors
- 2) {
602 for (j
= 0; j
< transports
[i
].num_protocols
; j
++) {
603 if (transports
[i
].protseq
[j
] != tower
->floors
[j
+2].lhs
.protocol
) {
608 if (j
== transports
[i
].num_protocols
) {
609 return transports
[i
].transport
;
613 /* Unknown transport */
614 return (unsigned int)-1;
617 _PUBLIC_
const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t
)
621 for (i
=0; i
<ARRAY_SIZE(transports
); i
++) {
622 if (t
== transports
[i
].transport
) {
623 return transports
[i
].name
;
629 _PUBLIC_ NTSTATUS
dcerpc_binding_from_tower(TALLOC_CTX
*mem_ctx
,
630 struct epm_tower
*tower
,
631 struct dcerpc_binding
**b_out
)
634 struct dcerpc_binding
*binding
;
636 binding
= talloc(mem_ctx
, struct dcerpc_binding
);
637 NT_STATUS_HAVE_NO_MEMORY(binding
);
639 ZERO_STRUCT(binding
->object
);
640 binding
->options
= NULL
;
641 binding
->host
= NULL
;
642 binding
->target_hostname
= NULL
;
644 binding
->assoc_group_id
= 0;
646 binding
->transport
= dcerpc_transport_by_tower(tower
);
648 if (binding
->transport
== (unsigned int)-1) {
649 return NT_STATUS_NOT_SUPPORTED
;
652 if (tower
->num_floors
< 1) {
656 /* Set object uuid */
657 status
= dcerpc_floor_get_lhs_data(&tower
->floors
[0], &binding
->object
);
659 if (!NT_STATUS_IS_OK(status
)) {
660 DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status
)));
664 /* Ignore floor 1, it contains the NDR version info */
666 binding
->options
= NULL
;
669 if (tower
->num_floors
>= 4) {
670 binding
->endpoint
= dcerpc_floor_get_rhs_data(mem_ctx
, &tower
->floors
[3]);
672 binding
->endpoint
= NULL
;
675 /* Set network address */
676 if (tower
->num_floors
>= 5) {
677 binding
->host
= dcerpc_floor_get_rhs_data(mem_ctx
, &tower
->floors
[4]);
678 NT_STATUS_HAVE_NO_MEMORY(binding
->host
);
679 binding
->target_hostname
= binding
->host
;
685 _PUBLIC_ NTSTATUS
dcerpc_binding_build_tower(TALLOC_CTX
*mem_ctx
,
686 const struct dcerpc_binding
*binding
,
687 struct epm_tower
*tower
)
689 const enum epm_protocol
*protseq
= NULL
;
690 int num_protocols
= -1, i
;
694 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
695 if (transports
[i
].transport
== binding
->transport
) {
696 protseq
= transports
[i
].protseq
;
697 num_protocols
= transports
[i
].num_protocols
;
702 if (num_protocols
== -1) {
703 DEBUG(0, ("Unable to find transport with id '%d'\n", binding
->transport
));
704 return NT_STATUS_UNSUCCESSFUL
;
707 tower
->num_floors
= 2 + num_protocols
;
708 tower
->floors
= talloc_array(mem_ctx
, struct epm_floor
, tower
->num_floors
);
711 tower
->floors
[0].lhs
.protocol
= EPM_PROTOCOL_UUID
;
713 tower
->floors
[0].lhs
.lhs_data
= dcerpc_floor_pack_lhs_data(tower
->floors
, &binding
->object
);
715 tower
->floors
[0].rhs
.uuid
.unknown
= dcerpc_floor_pack_rhs_if_version_data(tower
->floors
, &binding
->object
);
718 tower
->floors
[1].lhs
.protocol
= EPM_PROTOCOL_UUID
;
720 tower
->floors
[1].lhs
.lhs_data
= dcerpc_floor_pack_lhs_data(tower
->floors
,
721 &ndr_transfer_syntax
);
723 tower
->floors
[1].rhs
.uuid
.unknown
= data_blob_talloc_zero(tower
->floors
, 2);
725 /* Floor 2 to num_protocols */
726 for (i
= 0; i
< num_protocols
; i
++) {
727 tower
->floors
[2 + i
].lhs
.protocol
= protseq
[i
];
728 tower
->floors
[2 + i
].lhs
.lhs_data
= data_blob_talloc(tower
->floors
, NULL
, 0);
729 ZERO_STRUCT(tower
->floors
[2 + i
].rhs
);
730 dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[2 + i
], "");
733 /* The 4th floor contains the endpoint */
734 if (num_protocols
>= 2 && binding
->endpoint
) {
735 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[3], binding
->endpoint
);
736 if (NT_STATUS_IS_ERR(status
)) {
741 /* The 5th contains the network address */
742 if (num_protocols
>= 3 && binding
->host
) {
743 if (is_ipaddress(binding
->host
)) {
744 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[4],
747 /* note that we don't attempt to resolve the
748 name here - when we get a hostname here we
749 are in the client code, and want to put in
750 a wildcard all-zeros IP for the server to
752 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[4],
755 if (NT_STATUS_IS_ERR(status
)) {