From: Volker Lendecke Date: Sat, 12 Jun 2021 10:45:30 +0000 (+0200) Subject: rpc_server: Don't rely on TCP-bind() to return EADDRINUSE X-Git-Tag: tevent-0.11.0~381 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa147153c10b94e2db40d772677efacd5d0b31ee;p=thirdparty%2Fsamba.git 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/rpc_server/rpc_sock_helper.c b/source3/rpc_server/rpc_sock_helper.c index 22a0cd17aeb..8ae637a71b4 100644 --- a/source3/rpc_server/rpc_sock_helper.c +++ b/source3/rpc_server/rpc_sock_helper.c @@ -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; } }