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 "../../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"
35 #define MAX_PROTSEQ 10
39 enum dcerpc_transport_t transport
;
41 enum epm_protocol protseq
[MAX_PROTSEQ
];
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
},
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
},
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
}
96 const char *epm_floor_string(TALLOC_CTX
*mem_ctx
, struct epm_floor
*epm_floor
)
98 struct ndr_syntax_id syntax
;
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 */
108 if (GUID_equal(&syntax
.uuid
, &ndr_transfer_syntax
.uuid
)) {
112 if (GUID_equal(&syntax
.uuid
, &ndr64_transfer_syntax
.uuid
)) {
116 uuidstr
= GUID_string(mem_ctx
, &syntax
.uuid
);
118 return talloc_asprintf(mem_ctx
, " uuid %s/0x%02x", uuidstr
, syntax
.if_version
);
120 return talloc_asprintf(mem_ctx
, "IPX:%s",
121 data_blob_hex_string_upper(mem_ctx
, &epm_floor
->rhs
.uuid
.unknown
));
124 case EPM_PROTOCOL_NCACN
:
127 case EPM_PROTOCOL_NCADG
:
130 case EPM_PROTOCOL_NCALRPC
:
133 case EPM_PROTOCOL_DNET_NSP
:
136 case EPM_PROTOCOL_IP
:
137 return talloc_asprintf(mem_ctx
, "IP:%s", epm_floor
->rhs
.ip
.ipaddr
);
139 case EPM_PROTOCOL_NAMED_PIPE
:
140 return talloc_asprintf(mem_ctx
, "NAMED-PIPE:%s", epm_floor
->rhs
.named_pipe
.path
);
142 case EPM_PROTOCOL_SMB
:
143 return talloc_asprintf(mem_ctx
, "SMB:%s", epm_floor
->rhs
.smb
.unc
);
145 case EPM_PROTOCOL_UNIX_DS
:
146 return talloc_asprintf(mem_ctx
, "Unix:%s", epm_floor
->rhs
.unix_ds
.path
);
148 case EPM_PROTOCOL_NETBIOS
:
149 return talloc_asprintf(mem_ctx
, "NetBIOS:%s", epm_floor
->rhs
.netbios
.name
);
151 case EPM_PROTOCOL_NETBEUI
:
154 case EPM_PROTOCOL_SPX
:
157 case EPM_PROTOCOL_NB_IPX
:
160 case EPM_PROTOCOL_HTTP
:
161 return talloc_asprintf(mem_ctx
, "HTTP:%d", epm_floor
->rhs
.http
.port
);
163 case EPM_PROTOCOL_TCP
:
164 return talloc_asprintf(mem_ctx
, "TCP:%d", epm_floor
->rhs
.tcp
.port
);
166 case EPM_PROTOCOL_UDP
:
167 return talloc_asprintf(mem_ctx
, "UDP:%d", epm_floor
->rhs
.udp
.port
);
170 return talloc_asprintf(mem_ctx
, "UNK(%02x):", epm_floor
->lhs
.protocol
);
176 form a binding string from a binding structure
178 _PUBLIC_
char *dcerpc_binding_string(TALLOC_CTX
*mem_ctx
, const struct dcerpc_binding
*b
)
180 char *s
= talloc_strdup(mem_ctx
, "");
182 const char *t_name
= NULL
;
184 if (b
->transport
!= NCA_UNKNOWN
) {
185 t_name
= derpc_transport_string_by_transport(b
->transport
);
191 if (!GUID_all_zero(&b
->object
.uuid
)) {
192 s
= talloc_asprintf(s
, "%s@",
193 GUID_string(mem_ctx
, &b
->object
.uuid
));
196 if (t_name
!= NULL
) {
197 s
= talloc_asprintf_append_buffer(s
, "%s:", t_name
);
204 s
= talloc_asprintf_append_buffer(s
, "%s", b
->host
);
207 if (!b
->endpoint
&& !b
->options
&& !b
->flags
) {
211 s
= talloc_asprintf_append_buffer(s
, "[");
214 s
= talloc_asprintf_append_buffer(s
, "%s", b
->endpoint
);
217 /* this is a *really* inefficent way of dealing with strings,
218 but this is rarely called and the strings are always short,
220 for (i
=0;b
->options
&& b
->options
[i
];i
++) {
221 s
= talloc_asprintf_append_buffer(s
, ",%s", b
->options
[i
]);
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
,
231 s
= talloc_asprintf_append_buffer(s
, ",%s", ncacn_options
[i
].name
);
237 s
= talloc_asprintf_append_buffer(s
, "]");
243 parse a binding string into a dcerpc_binding structure
245 _PUBLIC_ NTSTATUS
dcerpc_parse_binding(TALLOC_CTX
*mem_ctx
, const char *s
, struct dcerpc_binding
**b_out
)
247 struct dcerpc_binding
*b
;
250 int i
, j
, comma_count
;
252 b
= talloc_zero(mem_ctx
, struct dcerpc_binding
);
254 return NT_STATUS_NO_MEMORY
;
259 if (p
&& PTR_DIFF(p
, s
) == 36) { /* 36 is the length of a UUID */
261 DATA_BLOB blob
= data_blob(s
, 36);
262 status
= GUID_from_data_blob(&blob
, &b
->object
.uuid
);
264 if (NT_STATUS_IS_ERR(status
)) {
265 DEBUG(0, ("Failed parsing UUID\n"));
271 ZERO_STRUCT(b
->object
);
274 b
->object
.if_version
= 0;
279 b
->transport
= NCA_UNKNOWN
;
281 char *type
= talloc_strndup(mem_ctx
, s
, PTR_DIFF(p
, s
));
283 return NT_STATUS_NO_MEMORY
;
286 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
287 if (strcasecmp(type
, transports
[i
].name
) == 0) {
288 b
->transport
= transports
[i
].transport
;
293 if (i
==ARRAY_SIZE(transports
)) {
294 DEBUG(0,("Unknown dcerpc transport '%s'\n", type
));
295 return NT_STATUS_INVALID_PARAMETER
;
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
;
310 options
[strlen(options
)-1] = 0;
312 b
->host
= talloc_strdup(b
, s
);
316 return NT_STATUS_NO_MEMORY
;
319 b
->target_hostname
= b
->host
;
323 b
->assoc_group_id
= 0;
325 b
->localaddress
= NULL
;
332 comma_count
= count_chars(options
, ',');
334 b
->options
= talloc_array(b
, const char *, comma_count
+2);
336 return NT_STATUS_NO_MEMORY
;
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
;
346 b
->options
[i
] = options
;
347 b
->options
[i
+1] = NULL
;
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) {
355 char c
= b
->options
[i
][opt_len
];
357 if (ncacn_options
[j
].flag
== DCERPC_LOCALADDRESS
&& c
== '=') {
358 b
->localaddress
= talloc_strdup(b
, &b
->options
[i
][opt_len
+1]);
363 b
->flags
|= ncacn_options
[j
].flag
;
364 for (k
=i
;b
->options
[k
];k
++) {
365 b
->options
[k
] = b
->options
[k
+1];
374 /* Endpoint is first option */
375 b
->endpoint
= b
->options
[0];
376 if (strlen(b
->endpoint
) == 0) b
->endpoint
= NULL
;
378 for (i
=0;b
->options
[i
];i
++) {
379 b
->options
[i
] = b
->options
[i
+1];
383 if (b
->options
[0] == NULL
)
390 _PUBLIC_ NTSTATUS
dcerpc_floor_get_lhs_data(const struct epm_floor
*epm_floor
,
391 struct ndr_syntax_id
*syntax
)
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;
398 ndr
= ndr_pull_init_blob(&epm_floor
->lhs
.lhs_data
, mem_ctx
);
400 talloc_free(mem_ctx
);
401 return NT_STATUS_NO_MEMORY
;
403 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
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
);
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
);
417 syntax
->if_version
= if_version
;
419 talloc_free(mem_ctx
);
424 static DATA_BLOB
dcerpc_floor_pack_lhs_data(TALLOC_CTX
*mem_ctx
, const struct ndr_syntax_id
*syntax
)
427 struct ndr_push
*ndr
= ndr_push_init_ctx(mem_ctx
);
429 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
431 ndr_push_GUID(ndr
, NDR_SCALARS
| NDR_BUFFERS
, &syntax
->uuid
);
432 ndr_push_uint16(ndr
, NDR_SCALARS
, syntax
->if_version
);
434 blob
= ndr_push_blob(ndr
);
435 talloc_steal(mem_ctx
, blob
.data
);
440 static DATA_BLOB
dcerpc_floor_pack_rhs_if_version_data(TALLOC_CTX
*mem_ctx
, const struct ndr_syntax_id
*syntax
)
443 struct ndr_push
*ndr
= ndr_push_init_ctx(mem_ctx
);
445 ndr
->flags
|= LIBNDR_FLAG_NOALIGN
;
447 ndr_push_uint16(ndr
, NDR_SCALARS
, syntax
->if_version
>> 16);
449 blob
= ndr_push_blob(ndr
);
450 talloc_steal(mem_ctx
, blob
.data
);
455 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX
*mem_ctx
, struct epm_floor
*epm_floor
)
457 switch (epm_floor
->lhs
.protocol
) {
458 case EPM_PROTOCOL_TCP
:
459 if (epm_floor
->rhs
.tcp
.port
== 0) return NULL
;
460 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.tcp
.port
);
462 case EPM_PROTOCOL_UDP
:
463 if (epm_floor
->rhs
.udp
.port
== 0) return NULL
;
464 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.udp
.port
);
466 case EPM_PROTOCOL_HTTP
:
467 if (epm_floor
->rhs
.http
.port
== 0) return NULL
;
468 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.http
.port
);
470 case EPM_PROTOCOL_IP
:
471 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.ip
.ipaddr
);
473 case EPM_PROTOCOL_NCACN
:
476 case EPM_PROTOCOL_NCADG
:
479 case EPM_PROTOCOL_SMB
:
480 if (strlen(epm_floor
->rhs
.smb
.unc
) == 0) return NULL
;
481 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.smb
.unc
);
483 case EPM_PROTOCOL_NAMED_PIPE
:
484 if (strlen(epm_floor
->rhs
.named_pipe
.path
) == 0) return NULL
;
485 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.named_pipe
.path
);
487 case EPM_PROTOCOL_NETBIOS
:
488 if (strlen(epm_floor
->rhs
.netbios
.name
) == 0) return NULL
;
489 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.netbios
.name
);
491 case EPM_PROTOCOL_NCALRPC
:
494 case EPM_PROTOCOL_VINES_SPP
:
495 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.vines_spp
.port
);
497 case EPM_PROTOCOL_VINES_IPC
:
498 return talloc_asprintf(mem_ctx
, "%d", epm_floor
->rhs
.vines_ipc
.port
);
500 case EPM_PROTOCOL_STREETTALK
:
501 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.streettalk
.streettalk
);
503 case EPM_PROTOCOL_UNIX_DS
:
504 if (strlen(epm_floor
->rhs
.unix_ds
.path
) == 0) return NULL
;
505 return talloc_strdup(mem_ctx
, epm_floor
->rhs
.unix_ds
.path
);
507 case EPM_PROTOCOL_NULL
:
511 DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor
->lhs
.protocol
));
518 static NTSTATUS
dcerpc_floor_set_rhs_data(TALLOC_CTX
*mem_ctx
,
519 struct epm_floor
*epm_floor
,
522 switch (epm_floor
->lhs
.protocol
) {
523 case EPM_PROTOCOL_TCP
:
524 epm_floor
->rhs
.tcp
.port
= atoi(data
);
527 case EPM_PROTOCOL_UDP
:
528 epm_floor
->rhs
.udp
.port
= atoi(data
);
531 case EPM_PROTOCOL_HTTP
:
532 epm_floor
->rhs
.http
.port
= atoi(data
);
535 case EPM_PROTOCOL_IP
:
536 epm_floor
->rhs
.ip
.ipaddr
= talloc_strdup(mem_ctx
, data
);
537 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.ip
.ipaddr
);
540 case EPM_PROTOCOL_NCACN
:
541 epm_floor
->rhs
.ncacn
.minor_version
= 0;
544 case EPM_PROTOCOL_NCADG
:
545 epm_floor
->rhs
.ncadg
.minor_version
= 0;
548 case EPM_PROTOCOL_SMB
:
549 epm_floor
->rhs
.smb
.unc
= talloc_strdup(mem_ctx
, data
);
550 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.smb
.unc
);
553 case EPM_PROTOCOL_NAMED_PIPE
:
554 epm_floor
->rhs
.named_pipe
.path
= talloc_strdup(mem_ctx
, data
);
555 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.named_pipe
.path
);
558 case EPM_PROTOCOL_NETBIOS
:
559 epm_floor
->rhs
.netbios
.name
= talloc_strdup(mem_ctx
, data
);
560 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.netbios
.name
);
563 case EPM_PROTOCOL_NCALRPC
:
566 case EPM_PROTOCOL_VINES_SPP
:
567 epm_floor
->rhs
.vines_spp
.port
= atoi(data
);
570 case EPM_PROTOCOL_VINES_IPC
:
571 epm_floor
->rhs
.vines_ipc
.port
= atoi(data
);
574 case EPM_PROTOCOL_STREETTALK
:
575 epm_floor
->rhs
.streettalk
.streettalk
= talloc_strdup(mem_ctx
, data
);
576 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.streettalk
.streettalk
);
579 case EPM_PROTOCOL_UNIX_DS
:
580 epm_floor
->rhs
.unix_ds
.path
= talloc_strdup(mem_ctx
, data
);
581 NT_STATUS_HAVE_NO_MEMORY(epm_floor
->rhs
.unix_ds
.path
);
584 case EPM_PROTOCOL_NULL
:
588 DEBUG(0,("Unsupported lhs protocol %d\n", epm_floor
->lhs
.protocol
));
592 return NT_STATUS_NOT_SUPPORTED
;
595 enum dcerpc_transport_t
dcerpc_transport_by_endpoint_protocol(int prot
)
599 /* Find a transport that has 'prot' as 4th protocol */
600 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
601 if (transports
[i
].num_protocols
>= 2 &&
602 transports
[i
].protseq
[1] == prot
) {
603 return transports
[i
].transport
;
607 /* Unknown transport */
608 return (unsigned int)-1;
611 _PUBLIC_
enum dcerpc_transport_t
dcerpc_transport_by_tower(const struct epm_tower
*tower
)
615 /* Find a transport that matches this tower */
616 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
618 if (transports
[i
].num_protocols
!= tower
->num_floors
- 2) {
622 for (j
= 0; j
< transports
[i
].num_protocols
; j
++) {
623 if (transports
[i
].protseq
[j
] != tower
->floors
[j
+2].lhs
.protocol
) {
628 if (j
== transports
[i
].num_protocols
) {
629 return transports
[i
].transport
;
633 /* Unknown transport */
634 return (unsigned int)-1;
637 _PUBLIC_
const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t
)
641 for (i
=0; i
<ARRAY_SIZE(transports
); i
++) {
642 if (t
== transports
[i
].transport
) {
643 return transports
[i
].name
;
649 _PUBLIC_ NTSTATUS
dcerpc_binding_from_tower(TALLOC_CTX
*mem_ctx
,
650 struct epm_tower
*tower
,
651 struct dcerpc_binding
**b_out
)
654 struct dcerpc_binding
*binding
;
656 binding
= talloc_zero(mem_ctx
, struct dcerpc_binding
);
657 NT_STATUS_HAVE_NO_MEMORY(binding
);
659 ZERO_STRUCT(binding
->object
);
660 binding
->options
= NULL
;
661 binding
->host
= NULL
;
662 binding
->target_hostname
= NULL
;
664 binding
->assoc_group_id
= 0;
666 binding
->transport
= dcerpc_transport_by_tower(tower
);
668 if (binding
->transport
== (unsigned int)-1) {
669 return NT_STATUS_NOT_SUPPORTED
;
672 if (tower
->num_floors
< 1) {
676 /* Set object uuid */
677 status
= dcerpc_floor_get_lhs_data(&tower
->floors
[0], &binding
->object
);
679 if (!NT_STATUS_IS_OK(status
)) {
680 DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status
)));
684 /* Ignore floor 1, it contains the NDR version info */
686 binding
->options
= NULL
;
689 if (tower
->num_floors
>= 4) {
690 binding
->endpoint
= dcerpc_floor_get_rhs_data(binding
, &tower
->floors
[3]);
692 binding
->endpoint
= NULL
;
695 /* Set network address */
696 if (tower
->num_floors
>= 5) {
697 binding
->host
= dcerpc_floor_get_rhs_data(binding
, &tower
->floors
[4]);
698 NT_STATUS_HAVE_NO_MEMORY(binding
->host
);
699 binding
->target_hostname
= binding
->host
;
705 _PUBLIC_
struct dcerpc_binding
*dcerpc_binding_dup(TALLOC_CTX
*mem_ctx
,
706 const struct dcerpc_binding
*b
)
708 struct dcerpc_binding
*n
;
711 n
= talloc_zero(mem_ctx
, struct dcerpc_binding
);
716 n
->transport
= b
->transport
;
717 n
->object
= b
->object
;
719 n
->assoc_group_id
= b
->assoc_group_id
;
721 if (b
->host
!= NULL
) {
722 n
->host
= talloc_strdup(n
, b
->host
);
723 if (n
->host
== NULL
) {
729 if (b
->target_hostname
!= NULL
) {
730 n
->target_hostname
= talloc_strdup(n
, b
->target_hostname
);
731 if (n
->target_hostname
== NULL
) {
737 if (b
->target_principal
!= NULL
) {
738 n
->target_principal
= talloc_strdup(n
, b
->target_principal
);
739 if (n
->target_principal
== NULL
) {
745 if (b
->localaddress
!= NULL
) {
746 n
->localaddress
= talloc_strdup(n
, b
->localaddress
);
747 if (n
->localaddress
== NULL
) {
753 if (b
->endpoint
!= NULL
) {
754 n
->endpoint
= talloc_strdup(n
, b
->endpoint
);
755 if (n
->endpoint
== NULL
) {
761 for (count
= 0; b
->options
&& b
->options
[count
]; count
++);
766 n
->options
= talloc_array(n
, const char *, count
+ 1);
767 if (n
->options
== NULL
) {
772 for (i
= 0; i
< count
; i
++) {
773 n
->options
[i
] = talloc_strdup(n
->options
, b
->options
[i
]);
774 if (n
->options
[i
] == NULL
) {
779 n
->options
[count
] = NULL
;
785 _PUBLIC_ NTSTATUS
dcerpc_binding_build_tower(TALLOC_CTX
*mem_ctx
,
786 const struct dcerpc_binding
*binding
,
787 struct epm_tower
*tower
)
789 const enum epm_protocol
*protseq
= NULL
;
790 int num_protocols
= -1, i
;
794 for (i
=0;i
<ARRAY_SIZE(transports
);i
++) {
795 if (transports
[i
].transport
== binding
->transport
) {
796 protseq
= transports
[i
].protseq
;
797 num_protocols
= transports
[i
].num_protocols
;
802 if (num_protocols
== -1) {
803 DEBUG(0, ("Unable to find transport with id '%d'\n", binding
->transport
));
804 return NT_STATUS_UNSUCCESSFUL
;
807 tower
->num_floors
= 2 + num_protocols
;
808 tower
->floors
= talloc_array(mem_ctx
, struct epm_floor
, tower
->num_floors
);
811 tower
->floors
[0].lhs
.protocol
= EPM_PROTOCOL_UUID
;
813 tower
->floors
[0].lhs
.lhs_data
= dcerpc_floor_pack_lhs_data(tower
->floors
, &binding
->object
);
815 tower
->floors
[0].rhs
.uuid
.unknown
= dcerpc_floor_pack_rhs_if_version_data(tower
->floors
, &binding
->object
);
818 tower
->floors
[1].lhs
.protocol
= EPM_PROTOCOL_UUID
;
820 tower
->floors
[1].lhs
.lhs_data
= dcerpc_floor_pack_lhs_data(tower
->floors
,
821 &ndr_transfer_syntax
);
823 tower
->floors
[1].rhs
.uuid
.unknown
= data_blob_talloc_zero(tower
->floors
, 2);
825 /* Floor 2 to num_protocols */
826 for (i
= 0; i
< num_protocols
; i
++) {
827 tower
->floors
[2 + i
].lhs
.protocol
= protseq
[i
];
828 tower
->floors
[2 + i
].lhs
.lhs_data
= data_blob_talloc(tower
->floors
, NULL
, 0);
829 ZERO_STRUCT(tower
->floors
[2 + i
].rhs
);
830 dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[2 + i
], "");
833 /* The 4th floor contains the endpoint */
834 if (num_protocols
>= 2 && binding
->endpoint
) {
835 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[3], binding
->endpoint
);
836 if (NT_STATUS_IS_ERR(status
)) {
841 /* The 5th contains the network address */
842 if (num_protocols
>= 3 && binding
->host
) {
843 if (is_ipaddress(binding
->host
) ||
844 (binding
->host
[0] == '\\' && binding
->host
[1] == '\\')) {
845 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[4],
848 /* note that we don't attempt to resolve the
849 name here - when we get a hostname here we
850 are in the client code, and want to put in
851 a wildcard all-zeros IP for the server to
853 status
= dcerpc_floor_set_rhs_data(tower
->floors
, &tower
->floors
[4],
856 if (NT_STATUS_IS_ERR(status
)) {