ndr: avoid object ACE pull overhead for non-object ACE
[Samba.git] / source3 / torture / test_oplock_cancel.c
blob86ce5b76d77c1982f69172e7cc5da9a435afce0e
1 /*
2 Unix SMB/CIFS implementation.
3 Test cleanup behaviour
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "locking/proto.h"
22 #include "torture/proto.h"
23 #include "system/filesys.h"
24 #include "system/select.h"
25 #include "libsmb/libsmb.h"
26 #include "libcli/smb/smbXcli_base.h"
27 #include "libcli/security/security.h"
28 #include "lib/util/tevent_ntstatus.h"
30 struct create_cancel_state {
31 uint8_t dummy;
34 static void create_cancel_done(struct tevent_req *subreq);
36 static struct tevent_req *create_cancel_send(
37 TALLOC_CTX *mem_ctx, struct tevent_context *ev,
38 struct cli_state *cli, const char *fname)
40 struct tevent_req *req, *subreq;
41 struct create_cancel_state *state;
43 req = tevent_req_create(mem_ctx, &state, struct create_cancel_state);
44 if (req == NULL) {
45 return NULL;
48 subreq = cli_ntcreate_send(
49 mem_ctx, ev, cli, fname, 0, FILE_GENERIC_READ,
50 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE,
51 FILE_OPEN_IF, 0, SMB2_IMPERSONATION_IMPERSONATION, 0);
52 if (tevent_req_nomem(subreq, req)) {
53 return tevent_req_post(req, ev);
55 if (!tevent_req_cancel(subreq)) {
56 tevent_req_oom(req);
57 return tevent_req_post(req, ev);
59 tevent_req_set_callback(subreq, create_cancel_done, req);
60 return req;
63 static void create_cancel_done(struct tevent_req *subreq)
65 struct tevent_req *req = tevent_req_callback_data(
66 subreq, struct tevent_req);
67 NTSTATUS status;
69 status = cli_ntcreate_recv(subreq, NULL, NULL);
70 TALLOC_FREE(subreq);
71 if (!NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) {
72 if (NT_STATUS_IS_OK(status)) {
73 status = NT_STATUS_UNSUCCESSFUL;
75 tevent_req_nterror(req, status);
76 return;
78 tevent_req_done(req);
81 static NTSTATUS create_cancel_recv(struct tevent_req *req)
83 return tevent_req_simple_recv_ntstatus(req);
86 static NTSTATUS create_cancel(struct cli_state *cli, const char *fname)
88 TALLOC_CTX *frame = talloc_stackframe();
89 struct tevent_context *ev;
90 struct tevent_req *req;
91 NTSTATUS status = NT_STATUS_NO_MEMORY;
93 ev = samba_tevent_context_init(frame);
94 if (ev == NULL) {
95 goto fail;
97 req = create_cancel_send(frame, ev, cli, fname);
98 if (req == NULL) {
99 goto fail;
101 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
102 goto fail;
104 status = create_cancel_recv(req);
105 fail:
106 TALLOC_FREE(frame);
107 return status;
110 bool run_oplock_cancel(int dummy)
112 struct cli_state *cli1, *cli2;
113 const char *fname = "oplock-cancel";
114 uint16_t fnum1;
115 NTSTATUS status;
117 * Currently this test seems to work only
118 * with SMB2/3 and only against Samba.
120 * TODO: we should change our server
121 * to ignore cancel for SMB2 Create
122 * and behave like Windows.
124 int flags = CLI_FULL_CONNECTION_DISABLE_SMB1;
126 if (!torture_open_connection_flags(&cli1, 0, flags)) {
127 return false;
129 cli1->use_oplocks = true;
131 if (!torture_open_connection_flags(&cli2, 0, flags)) {
132 return false;
134 cli2->use_oplocks = true;
136 status = cli_ntcreate(
137 cli1, fname, 0, FILE_GENERIC_READ, FILE_ATTRIBUTE_NORMAL,
138 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0,
139 &fnum1, NULL);
140 if (!NT_STATUS_IS_OK(status)) {
141 d_printf("cli_ntcreate failed: %s\n", nt_errstr(status));
142 return false;
145 status = create_cancel(cli2, fname);
146 if (!NT_STATUS_IS_OK(status)) {
147 d_printf("create_cancel failed: %s\n", nt_errstr(status));
148 return false;
151 cli_close(cli1, fnum1);
153 TALLOC_FREE(cli1);
156 * Give cli1's smbd time to inform cli2's smbd
158 smb_msleep(5000);
160 status = cli_unlink(cli2, fname,
161 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
162 if (!NT_STATUS_IS_OK(status)) {
163 d_printf("cli_unlink failed: %s\n", nt_errstr(status));
164 return false;
167 return true;