30863a9167e897c7119ab22f24e24f44b2dd6948
[jarrpa/samba-autobuild/.git] / source4 / torture / smb2 / oplock_break_handler.c
1 /*
2  * Unix SMB/CIFS implementation.
3  *
4  * test suite for SMB2 replay
5  *
6  * Copyright (C) Anubhav Rakshit 2014
7  * Copyright (C) Stefan Metzmacher 2014
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "includes.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28 #include "../libcli/smb/smbXcli_base.h"
29 #include "oplock_break_handler.h"
30
31 struct break_info break_info;
32
33 static void torture_oplock_ack_callback(struct smb2_request *req)
34 {
35         NTSTATUS status;
36
37         status = smb2_break_recv(req, &break_info.br);
38         if (!NT_STATUS_IS_OK(status)) {
39                 break_info.failures++;
40                 break_info.failure_status = status;
41         }
42 }
43
44 /**
45  * A general oplock break notification handler.  This should be used when a
46  * test expects to break from batch or exclusive to a lower level.
47  */
48
49 bool torture_oplock_ack_handler(struct smb2_transport *transport,
50                                 const struct smb2_handle *handle,
51                                 uint8_t level,
52                                 void *private_data)
53 {
54         struct smb2_tree *tree = private_data;
55         const char *name;
56         struct smb2_request *req;
57
58         ZERO_STRUCT(break_info.br);
59
60         break_info.handle       = *handle;
61         break_info.level        = level;
62         break_info.count++;
63
64         switch (level) {
65         case SMB2_OPLOCK_LEVEL_II:
66                 name = "level II";
67                 break;
68         case SMB2_OPLOCK_LEVEL_NONE:
69                 name = "none";
70                 break;
71         default:
72                 name = "unknown";
73                 break_info.failures++;
74         }
75         torture_comment(break_info.tctx,
76                         "transport[%p] Acking to %s [0x%02X] in oplock handler\n",
77                         transport, name, level);
78
79         break_info.br.in.file.handle    = *handle;
80         break_info.br.in.oplock_level   = level;
81         break_info.br.in.reserved       = 0;
82         break_info.br.in.reserved2      = 0;
83         break_info.received_transport = tree->session->transport;
84         SMB_ASSERT(tree->session->transport == transport);
85
86         req = smb2_break_send(tree, &break_info.br);
87         req->async.fn = torture_oplock_ack_callback;
88         req->async.private_data = NULL;
89
90         return true;
91 }