1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

rpc_server: Don't rely on TCP-bind() to return EADDRINUSE

socket_wrapper can't do EADDRINUSE because unix domain sockets don't
do it.

This currently works correctly because right now all RPC servers
either use explicit ports or all listen on the same socket.

The new code uses a static variable, so it only helps if a single
process listens for multiple RPC sockets. It won't work if multiple
processes start listening. But in case samba-dcerpcd goes in this will
be exactly the right thing to do.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2021-06-12 12:45:30 +02:00 committed by Jeremy Allison
parent 582030bae2
commit aa147153c1

View File

@ -117,12 +117,18 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(
int fd = -1;
if (*port == 0) {
static uint16_t low = 0;
uint16_t i;
for (i = lp_rpc_low_port(); i <= lp_rpc_high_port(); i++) {
if (low == 0) {
low = lp_rpc_low_port();
}
for (i = low; i <= lp_rpc_high_port(); i++) {
fd = open_socket_in(SOCK_STREAM, ifss, i, false);
if (fd >= 0) {
*port = i;
low = i+1;
break;
}
}