rpc_server3: Use fdopen_keepfd()
authorVolker Lendecke <vl@samba.org>
Wed, 10 Apr 2024 11:08:06 +0000 (13:08 +0200)
committerMartin Schwenke <martins@samba.org>
Tue, 16 Apr 2024 23:51:45 +0000 (23:51 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
source3/rpc_server/rpc_host.c
source3/rpc_server/rpc_worker.c

index 7c5785f3a3bbe58b375a6a2b10224853839eb0ad..7784261cf8b77256645da5aff831f3b01458781a 100644 (file)
@@ -2309,7 +2309,6 @@ static bool rpc_host_dump_status_filter(
        struct rpc_server **servers = host->servers;
        size_t i, num_servers = talloc_array_length(servers);
        FILE *f = NULL;
-       int fd;
 
        if (rec->msg_type != MSG_RPC_DUMP_STATUS) {
                return false;
@@ -2319,18 +2318,9 @@ static bool rpc_host_dump_status_filter(
                return false;
        }
 
-       fd = dup(rec->fds[0]);
-       if (fd == -1) {
-               DBG_DEBUG("dup(%"PRIi64") failed: %s\n",
-                         rec->fds[0],
-                         strerror(errno));
-               return false;
-       }
-
-       f = fdopen(fd, "w");
+       f = fdopen_keepfd(rec->fds[0], "w");
        if (f == NULL) {
                DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
-               close(fd);
                return false;
        }
 
index bf9671d3c156939328c2148776822e8d205c8e45..81c7a90972180391a53fd6e2b3412e80c79ecfce 100644 (file)
@@ -24,6 +24,7 @@
 #include "source3/librpc/gen_ndr/ndr_rpc_host.h"
 #include "lib/util/debug.h"
 #include "lib/util/fault.h"
+#include "lib/util/util_file.h"
 #include "rpc_server.h"
 #include "rpc_pipes.h"
 #include "source3/smbd/proto.h"
@@ -569,7 +570,6 @@ static bool rpc_worker_status_filter(
                private_data, struct rpc_worker);
        struct dcerpc_ncacn_conn *conn = NULL;
        FILE *f = NULL;
-       int fd;
 
        if (rec->msg_type != MSG_RPC_DUMP_STATUS) {
                return false;
@@ -580,18 +580,9 @@ static bool rpc_worker_status_filter(
                return false;
        }
 
-       fd = dup(rec->fds[0]);
-       if (fd == -1) {
-               DBG_DEBUG("dup(%"PRIi64") failed: %s\n",
-                         rec->fds[0],
-                         strerror(errno));
-               return false;
-       }
-
-       f = fdopen(fd, "w");
+       f = fdopen_keepfd(rec->fds[0], "w");
        if (f == NULL) {
-               DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
-               close(fd);
+               DBG_DEBUG("fdopen_keepfd failed: %s\n", strerror(errno));
                return false;
        }