s3:torture: add test LOCAL-MESSAGING-FDPASS1
[samba.git] / source3 / torture / test_messaging_fd_passing.c
1 /*
2    Unix SMB/CIFS implementation.
3    Test for fd passing with messaging
4
5    Copyright (C) Michael Adam 2014
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "torture/proto.h"
23 #include "lib/util/tevent_unix.h"
24 #include "messages.h"
25
26 /**
27  * test fdpass1:
28  *
29  * Try to pass an fd to the sending process - fails.
30  */
31 bool run_messaging_fdpass1(int dummy)
32 {
33         struct tevent_context *ev = NULL;
34         struct messaging_context *msg_ctx = NULL;
35         bool retval = false;
36         int pipe_fds[2];
37         int pass_fds[1] = { 0 };
38         int ret;
39         NTSTATUS status;
40         struct server_id dst;
41         TALLOC_CTX *frame = talloc_stackframe();
42
43         ev = samba_tevent_context_init(frame);
44         if (ev == NULL) {
45                 fprintf(stderr, "tevent_context_init failed\n");
46                 goto fail;
47         }
48         msg_ctx = messaging_init(ev, ev);
49         if (msg_ctx == NULL) {
50                 fprintf(stderr, "messaging_init failed\n");
51                 goto fail;
52         }
53
54         dst = messaging_server_id(msg_ctx);
55
56         ret = pipe(pipe_fds);
57         if (ret != 0) {
58                 perror("pipe failed");
59                 goto fail;
60         }
61
62         pass_fds[0] = pipe_fds[0];
63
64         status = messaging_send_iov(msg_ctx, dst, MSG_PING, NULL, 0,
65                                     pass_fds, 1);
66         if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
67                 fprintf(stderr,
68                         "messaging_send_iov gave: %s\n", nt_errstr(status));
69                 goto fail;
70         }
71
72         retval = true;
73
74 fail:
75         TALLOC_FREE(frame);
76         return retval;
77 }