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 "librpc/rpc/dcesrv_core.h"
28 #include "rpc_server/rpc_sock_helper.h"
29 #include "lib/server_prefork.h"
30 #include "librpc/ndr/ndr_table.h"
33 #define DBGC_CLASS DBGC_RPC_SRV
35 NTSTATUS
dcesrv_create_ncacn_ip_tcp_sockets(struct dcesrv_endpoint
*e
,
36 struct pf_listen_fd
*listen_fd
,
40 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
43 const char *endpoint
= NULL
;
45 tmp_ctx
= talloc_stackframe();
46 if (tmp_ctx
== NULL
) {
47 return NT_STATUS_NO_MEMORY
;
50 endpoint
= dcerpc_binding_get_string_option(e
->ep_description
,
52 if (endpoint
!= NULL
) {
53 port
= atoi(endpoint
);
56 if (lp_interfaces() && lp_bind_interfaces_only()) {
57 uint32_t num_ifs
= iface_count();
61 * We have been given an interfaces line, and been told to only
62 * bind to those interfaces. Create a socket per interface and
66 /* Now open a listen socket for each of the interfaces. */
67 for (i
= 0; i
< num_ifs
; i
++) {
68 const struct sockaddr_storage
*ifss
=
69 iface_n_sockaddr_storage(i
);
72 status
= dcesrv_create_ncacn_ip_tcp_socket(ifss
,
75 if (!NT_STATUS_IS_OK(status
)) {
78 listen_fd
[*listen_fd_size
].fd
= fd
;
79 listen_fd
[*listen_fd_size
].fd_data
= e
;
83 const char *sock_addr
;
88 sock_addr
= "::,0.0.0.0";
90 sock_addr
= "0.0.0.0";
93 for (sock_ptr
= sock_addr
;
94 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
96 struct sockaddr_storage ss
;
99 /* open an incoming socket */
100 if (!interpret_string_addr(&ss
,
102 AI_NUMERICHOST
|AI_PASSIVE
)) {
106 status
= dcesrv_create_ncacn_ip_tcp_socket(&ss
,
109 if (!NT_STATUS_IS_OK(status
)) {
112 listen_fd
[*listen_fd_size
].fd
= fd
;
113 listen_fd
[*listen_fd_size
].fd_data
= e
;
118 /* Set the port in the endpoint */
119 snprintf(port_str
, sizeof(port_str
), "%u", port
);
121 status
= dcerpc_binding_set_string_option(e
->ep_description
,
122 "endpoint", port_str
);
123 if (!NT_STATUS_IS_OK(status
)) {
124 DBG_ERR("Failed to set binding endpoint '%s': %s\n",
125 port_str
, nt_errstr(status
));
129 status
= NT_STATUS_OK
;
131 talloc_free(tmp_ctx
);
135 NTSTATUS
dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context
*ev_ctx
,
136 struct messaging_context
*msg_ctx
,
137 struct dcesrv_context
*dce_ctx
,
138 struct dcesrv_endpoint
*e
,
139 dcerpc_ncacn_termination_fn t_fn
,
145 tmp_ctx
= talloc_stackframe();
146 if (tmp_ctx
== NULL
) {
147 return NT_STATUS_NO_MEMORY
;
150 if (lp_interfaces() && lp_bind_interfaces_only()) {
151 uint32_t num_ifs
= iface_count();
155 * We have been given an interfaces line, and been told to only
156 * bind to those interfaces. Create a socket per interface and
157 * bind to only these.
160 /* Now open a listen socket for each of the interfaces. */
161 for (i
= 0; i
< num_ifs
; i
++) {
162 const struct sockaddr_storage
*ifss
=
163 iface_n_sockaddr_storage(i
);
165 status
= dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx
,
172 if (!NT_STATUS_IS_OK(status
)) {
177 const char *sock_addr
;
178 const char *sock_ptr
;
182 sock_addr
= "::,0.0.0.0";
184 sock_addr
= "0.0.0.0";
187 for (sock_ptr
= sock_addr
;
188 next_token_talloc(talloc_tos(), &sock_ptr
, &sock_tok
, " \t,");
190 struct sockaddr_storage ss
;
192 /* open an incoming socket */
193 if (!interpret_string_addr(&ss
,
195 AI_NUMERICHOST
|AI_PASSIVE
)) {
199 status
= dcesrv_setup_ncacn_ip_tcp_socket(ev_ctx
,
206 if (!NT_STATUS_IS_OK(status
)) {
212 status
= NT_STATUS_OK
;
214 talloc_free(tmp_ctx
);
218 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */