dca0e96cb4a2a23bbec761869c07a703db5b777f
[ira/wip.git] / source3 / libsmb / clioplock.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    SMB client oplock functions
5    Copyright (C) Andrew Tridgell 2001
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #define NO_SYSLOG
23
24 #include "includes.h"
25
26 /****************************************************************************
27 send an ack for an oplock break request
28 ****************************************************************************/
29 BOOL cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level)
30 {
31         char *oldbuf = cli->outbuf;
32         pstring buf;
33         BOOL ret;
34
35         cli->outbuf = buf;
36
37         memset(buf,'\0',smb_size);
38         set_message(buf,8,0,True);
39
40         SCVAL(buf,smb_com,SMBlockingX);
41         SSVAL(buf,smb_tid, cli->cnum);
42         cli_setup_packet(cli);
43         SSVAL(buf,smb_vwv0,0xFF);
44         SSVAL(buf,smb_vwv1,0);
45         SSVAL(buf,smb_vwv2,fnum);
46         if (level == 1)
47                 SSVAL(buf,smb_vwv3,0x102); /* levelII oplock break ack */
48         else
49                 SSVAL(buf,smb_vwv3,2); /* exclusive oplock break ack */
50         SIVAL(buf,smb_vwv4,0); /* timoeut */
51         SSVAL(buf,smb_vwv6,0); /* unlockcount */
52         SSVAL(buf,smb_vwv7,0); /* lockcount */
53
54         ret = cli_send_smb(cli);        
55
56         cli->outbuf = oldbuf;
57
58         return ret;
59 }
60
61
62 /****************************************************************************
63 set the oplock handler for a connection
64 ****************************************************************************/
65 void cli_oplock_handler(struct cli_state *cli, 
66                         BOOL (*handler)(struct cli_state *, int, unsigned char))
67 {
68         cli->oplock_handler = handler;
69 }