2 * Unix SMB/CIFS implementation.
6 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "../lib/tsocket/tsocket.h"
26 #include "librpc/rpc/dcerpc_ep.h"
27 #include "rpc_server/rpc_server.h"
28 #include "rpc_server/rpc_sock_helper.h"
30 NTSTATUS
rpc_create_tcpip_sockets(const struct ndr_interface_table
*iface
,
31 struct dcerpc_binding_vector
*bvec
,
36 uint32_t num_ifs
= iface_count();
40 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
43 tmp_ctx
= talloc_stackframe();
44 if (tmp_ctx
== NULL
) {
45 return NT_STATUS_NO_MEMORY
;
48 if (lp_interfaces() && lp_bind_interfaces_only()) {
50 * We have been given an interfaces line, and been told to only
51 * bind to those interfaces. Create a socket per interface and
55 /* Now open a listen socket for each of the interfaces. */
56 for (i
= 0; i
< num_ifs
; i
++) {
57 const struct sockaddr_storage
*ifss
=
58 iface_n_sockaddr_storage(i
);
59 struct tsocket_address
*bind_addr
;
63 fd
= create_tcpip_socket(ifss
, &p
);
64 if (fd
< 0 || p
== 0) {
65 status
= NT_STATUS_UNSUCCESSFUL
;
71 listen_fd
[*listen_fd_size
] = fd
;
75 rc
= tsocket_address_bsd_from_sockaddr(tmp_ctx
,
76 (const struct sockaddr
*)ifss
,
77 sizeof(struct sockaddr_storage
),
81 status
= NT_STATUS_NO_MEMORY
;
85 addr
= tsocket_address_inet_addr_string(bind_addr
,
89 status
= NT_STATUS_NO_MEMORY
;
93 status
= dcerpc_binding_vector_add_port(iface
,
97 if (!NT_STATUS_IS_OK(status
)) {
104 const char *sock_addr
;
105 const char *sock_ptr
;
109 sock_addr
= "::,0.0.0.0";
111 sock_addr
= "0.0.0.0";
114 for (sock_ptr
= sock_addr
;
115 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
117 struct sockaddr_storage ss
;
120 /* open an incoming socket */
121 if (!interpret_string_addr(&ss
,
123 AI_NUMERICHOST
|AI_PASSIVE
)) {
127 fd
= create_tcpip_socket(&ss
, &p
);
128 if (fd
< 0 || p
== 0) {
129 status
= NT_STATUS_UNSUCCESSFUL
;
135 listen_fd
[*listen_fd_size
] = fd
;
139 status
= dcerpc_binding_vector_add_port(iface
,
143 if (!NT_STATUS_IS_OK(status
)) {
151 status
= NT_STATUS_OK
;
153 talloc_free(tmp_ctx
);
157 NTSTATUS
rpc_setup_tcpip_sockets(struct tevent_context
*ev_ctx
,
158 struct messaging_context
*msg_ctx
,
159 const struct ndr_interface_table
*iface
,
160 struct dcerpc_binding_vector
*bvec
,
163 uint32_t num_ifs
= iface_count();
167 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
170 tmp_ctx
= talloc_stackframe();
171 if (tmp_ctx
== NULL
) {
172 return NT_STATUS_NO_MEMORY
;
175 if (lp_interfaces() && lp_bind_interfaces_only()) {
177 * We have been given an interfaces line, and been told to only
178 * bind to those interfaces. Create a socket per interface and
179 * bind to only these.
182 /* Now open a listen socket for each of the interfaces. */
183 for (i
= 0; i
< num_ifs
; i
++) {
184 const struct sockaddr_storage
*ifss
=
185 iface_n_sockaddr_storage(i
);
186 struct tsocket_address
*bind_addr
;
189 p
= setup_dcerpc_ncacn_tcpip_socket(ev_ctx
,
194 status
= NT_STATUS_UNSUCCESSFUL
;
199 rc
= tsocket_address_bsd_from_sockaddr(tmp_ctx
,
200 (const struct sockaddr
*)ifss
,
201 sizeof(struct sockaddr_storage
),
204 status
= NT_STATUS_NO_MEMORY
;
208 addr
= tsocket_address_inet_addr_string(bind_addr
,
211 status
= NT_STATUS_NO_MEMORY
;
215 status
= dcerpc_binding_vector_add_port(iface
,
219 if (!NT_STATUS_IS_OK(status
)) {
225 const char *sock_addr
;
226 const char *sock_ptr
;
230 sock_addr
= "::,0.0.0.0";
232 sock_addr
= "0.0.0.0";
235 for (sock_ptr
= sock_addr
;
236 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
238 struct sockaddr_storage ss
;
240 /* open an incoming socket */
241 if (!interpret_string_addr(&ss
,
243 AI_NUMERICHOST
|AI_PASSIVE
)) {
247 p
= setup_dcerpc_ncacn_tcpip_socket(ev_ctx
,
252 status
= NT_STATUS_UNSUCCESSFUL
;
257 status
= dcerpc_binding_vector_add_port(iface
,
261 if (!NT_STATUS_IS_OK(status
)) {
268 status
= NT_STATUS_OK
;
270 talloc_free(tmp_ctx
);
274 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */