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"
29 #include "lib/server_prefork.h"
32 #define DBGC_CLASS DBGC_RPC_SRV
34 NTSTATUS
dcesrv_create_ncacn_ip_tcp_sockets(
35 const struct ndr_interface_table
*iface
,
36 struct dcerpc_binding_vector
*bvec
,
38 struct pf_listen_fd
*listen_fd
,
41 uint32_t num_ifs
= iface_count();
45 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
48 tmp_ctx
= talloc_stackframe();
49 if (tmp_ctx
== NULL
) {
50 return NT_STATUS_NO_MEMORY
;
53 if (lp_interfaces() && lp_bind_interfaces_only()) {
55 * We have been given an interfaces line, and been told to only
56 * bind to those interfaces. Create a socket per interface and
60 /* Now open a listen socket for each of the interfaces. */
61 for (i
= 0; i
< num_ifs
; i
++) {
62 const struct sockaddr_storage
*ifss
=
63 iface_n_sockaddr_storage(i
);
64 struct tsocket_address
*bind_addr
;
68 status
= dcesrv_create_ncacn_ip_tcp_socket(ifss
,
71 if (!NT_STATUS_IS_OK(status
)) {
74 listen_fd
[*listen_fd_size
].fd
= fd
;
75 listen_fd
[*listen_fd_size
].fd_data
= NULL
;
79 rc
= tsocket_address_bsd_from_sockaddr(tmp_ctx
,
80 (const struct sockaddr
*)ifss
,
81 sizeof(struct sockaddr_storage
),
85 status
= NT_STATUS_NO_MEMORY
;
89 addr
= tsocket_address_inet_addr_string(bind_addr
,
93 status
= NT_STATUS_NO_MEMORY
;
97 status
= dcerpc_binding_vector_add_port(iface
,
101 if (!NT_STATUS_IS_OK(status
)) {
108 const char *sock_addr
;
109 const char *sock_ptr
;
113 sock_addr
= "::,0.0.0.0";
115 sock_addr
= "0.0.0.0";
118 for (sock_ptr
= sock_addr
;
119 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
121 struct sockaddr_storage ss
;
124 /* open an incoming socket */
125 if (!interpret_string_addr(&ss
,
127 AI_NUMERICHOST
|AI_PASSIVE
)) {
131 status
= dcesrv_create_ncacn_ip_tcp_socket(&ss
,
134 if (!NT_STATUS_IS_OK(status
)) {
137 listen_fd
[*listen_fd_size
].fd
= fd
;
138 listen_fd
[*listen_fd_size
].fd_data
= NULL
;
142 status
= dcerpc_binding_vector_add_port(iface
,
146 if (!NT_STATUS_IS_OK(status
)) {
154 status
= NT_STATUS_OK
;
156 talloc_free(tmp_ctx
);
160 NTSTATUS
dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context
*ev_ctx
,
161 struct messaging_context
*msg_ctx
,
162 const struct ndr_interface_table
*iface
,
163 struct dcerpc_binding_vector
*bvec
,
166 uint32_t num_ifs
= iface_count();
170 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
173 tmp_ctx
= talloc_stackframe();
174 if (tmp_ctx
== NULL
) {
175 return NT_STATUS_NO_MEMORY
;
178 if (lp_interfaces() && lp_bind_interfaces_only()) {
180 * We have been given an interfaces line, and been told to only
181 * bind to those interfaces. Create a socket per interface and
182 * bind to only these.
185 /* Now open a listen socket for each of the interfaces. */
186 for (i
= 0; i
< num_ifs
; i
++) {
187 const struct sockaddr_storage
*ifss
=
188 iface_n_sockaddr_storage(i
);
189 struct tsocket_address
*bind_addr
;
192 status
= dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx
,
196 if (!NT_STATUS_IS_OK(status
)) {
201 rc
= tsocket_address_bsd_from_sockaddr(tmp_ctx
,
202 (const struct sockaddr
*)ifss
,
203 sizeof(struct sockaddr_storage
),
206 status
= NT_STATUS_NO_MEMORY
;
210 addr
= tsocket_address_inet_addr_string(bind_addr
,
213 status
= NT_STATUS_NO_MEMORY
;
217 status
= dcerpc_binding_vector_add_port(iface
,
221 if (!NT_STATUS_IS_OK(status
)) {
227 const char *sock_addr
;
228 const char *sock_ptr
;
232 sock_addr
= "::,0.0.0.0";
234 sock_addr
= "0.0.0.0";
237 for (sock_ptr
= sock_addr
;
238 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
240 struct sockaddr_storage ss
;
242 /* open an incoming socket */
243 if (!interpret_string_addr(&ss
,
245 AI_NUMERICHOST
|AI_PASSIVE
)) {
249 status
= dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx
,
253 if (!NT_STATUS_IS_OK(status
)) {
258 status
= dcerpc_binding_vector_add_port(iface
,
262 if (!NT_STATUS_IS_OK(status
)) {
269 status
= NT_STATUS_OK
;
271 talloc_free(tmp_ctx
);
275 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */