s3:torture: add test LOCAL-MESSAGING-FDPASS1
authorMichael Adam <obnox@samba.org>
Mon, 18 Aug 2014 16:20:34 +0000 (18:20 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 24 Sep 2014 06:44:12 +0000 (08:44 +0200)
Verify that a process can not pass an fd to itself.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/torture/proto.h
source3/torture/test_messaging_fd_passing.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 08790c758e9b27790dcd6cf90101aa96d059f955..0402f1a7c9ff6d6afb63bb094b34fb35029843ab 100644 (file)
@@ -116,6 +116,7 @@ bool run_bench_pthreadpool(int dummy);
 bool run_messaging_read1(int dummy);
 bool run_messaging_read2(int dummy);
 bool run_messaging_read3(int dummy);
+bool run_messaging_fdpass1(int dummy);
 bool run_oplock_cancel(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_messaging_fd_passing.c b/source3/torture/test_messaging_fd_passing.c
new file mode 100644 (file)
index 0000000..b860939
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+   Unix SMB/CIFS implementation.
+   Test for fd passing with messaging
+
+   Copyright (C) Michael Adam 2014
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/proto.h"
+#include "lib/util/tevent_unix.h"
+#include "messages.h"
+
+/**
+ * test fdpass1:
+ *
+ * Try to pass an fd to the sending process - fails.
+ */
+bool run_messaging_fdpass1(int dummy)
+{
+       struct tevent_context *ev = NULL;
+       struct messaging_context *msg_ctx = NULL;
+       bool retval = false;
+       int pipe_fds[2];
+       int pass_fds[1] = { 0 };
+       int ret;
+       NTSTATUS status;
+       struct server_id dst;
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               fprintf(stderr, "tevent_context_init failed\n");
+               goto fail;
+       }
+       msg_ctx = messaging_init(ev, ev);
+       if (msg_ctx == NULL) {
+               fprintf(stderr, "messaging_init failed\n");
+               goto fail;
+       }
+
+       dst = messaging_server_id(msg_ctx);
+
+       ret = pipe(pipe_fds);
+       if (ret != 0) {
+               perror("pipe failed");
+               goto fail;
+       }
+
+       pass_fds[0] = pipe_fds[0];
+
+       status = messaging_send_iov(msg_ctx, dst, MSG_PING, NULL, 0,
+                                   pass_fds, 1);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
+               fprintf(stderr,
+                       "messaging_send_iov gave: %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       retval = true;
+
+fail:
+       TALLOC_FREE(frame);
+       return retval;
+}
index 799afc71dffbc324d2179c31811d12601678c753..b3d9237ba3a35f9e39a024b9e45b802b69559ac1 100644 (file)
@@ -9606,6 +9606,7 @@ static struct {
        { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
        { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
        { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },
+       { "LOCAL-MESSAGING-FDPASS1", run_messaging_fdpass1, 0 },
        { "LOCAL-BASE64", run_local_base64, 0},
        { "LOCAL-RBTREE", run_local_rbtree, 0},
        { "LOCAL-MEMCACHE", run_local_memcache, 0},
index 740ab765148c48aeb78d1258b3feffef2e7acb0e..ca46dad68bf37bc68cf12ccfaa818d9666abcdf4 100755 (executable)
@@ -1252,6 +1252,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                  torture/test_dbwrap_ctdb.c
                  torture/test_buffersize.c
                  torture/test_messaging_read.c
+                 torture/test_messaging_fd_passing.c
                  torture/test_oplock_cancel.c
                  torture/t_strappend.c
                  torture/bench_pthreadpool.c