summaryrefslogtreecommitdiff
path: root/source3/torture/test_messaging_fd_passing.c
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2014-08-18 18:20:34 +0200
committerMichael Adam <obnox@samba.org>2014-09-24 08:44:12 +0200
commitdb809c5eb494fe345b43b0f30cfa4e61004f6f22 (patch)
treefdb77ec9a0062f5d736f3dd15ff0bd0eb92ca8ce /source3/torture/test_messaging_fd_passing.c
parent01026363dd0051eac00b555c5e0503a0484134cc (diff)
downloadsamba-db809c5eb494fe345b43b0f30cfa4e61004f6f22.tar.gz
s3:torture: add test LOCAL-MESSAGING-FDPASS1
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>
Diffstat (limited to 'source3/torture/test_messaging_fd_passing.c')
-rw-r--r--source3/torture/test_messaging_fd_passing.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/source3/torture/test_messaging_fd_passing.c b/source3/torture/test_messaging_fd_passing.c
new file mode 100644
index 00000000000..b860939d46e
--- /dev/null
+++ b/source3/torture/test_messaging_fd_passing.c
@@ -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;
+}