Merge commit 'release-4-0-0alpha1' into v4-0-test
[kai/samba.git] / source / libcli / smb2 / setinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 client setinfo calls
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26
27 /*
28   send a setinfo request
29 */
30 struct smb2_request *smb2_setinfo_send(struct smb2_tree *tree, struct smb2_setinfo *io)
31 {
32         NTSTATUS status;
33         struct smb2_request *req;
34
35         req = smb2_request_init_tree(tree, SMB2_OP_SETINFO, 0x20, true, io->in.blob.length);
36         if (req == NULL) return NULL;
37
38         SSVAL(req->out.body, 0x02, io->in.level);
39
40         status = smb2_push_s32o32_blob(&req->out, 0x04, io->in.blob);
41         if (!NT_STATUS_IS_OK(status)) {
42                 talloc_free(req);
43                 return NULL;
44         }
45
46         SIVAL(req->out.body, 0x0C, io->in.flags);
47         smb2_push_handle(req->out.body+0x10, &io->in.file.handle);
48
49         smb2_transport_send(req);
50
51         return req;
52 }
53
54
55 /*
56   recv a setinfo reply
57 */
58 NTSTATUS smb2_setinfo_recv(struct smb2_request *req)
59 {
60         if (!smb2_request_receive(req) || 
61             !smb2_request_is_ok(req)) {
62                 return smb2_request_destroy(req);
63         }
64
65         SMB2_CHECK_PACKET_RECV(req, 0x02, false);
66
67         return smb2_request_destroy(req);
68 }
69
70 /*
71   sync setinfo request
72 */
73 NTSTATUS smb2_setinfo(struct smb2_tree *tree, struct smb2_setinfo *io)
74 {
75         struct smb2_request *req = smb2_setinfo_send(tree, io);
76         return smb2_setinfo_recv(req);
77 }
78
79 /*
80   level specific file setinfo call - async send
81 */
82 struct smb2_request *smb2_setinfo_file_send(struct smb2_tree *tree, union smb_setfileinfo *io)
83 {
84         struct smb2_setinfo b;
85         uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FILE);
86         struct smb2_request *req;
87         
88         if (smb2_level == 0) {
89                 return NULL;
90         }
91
92         ZERO_STRUCT(b);
93         b.in.level             = smb2_level;
94         b.in.file.handle       = io->generic.in.file.handle;
95         if (!smb_raw_setfileinfo_passthru(tree, io->generic.level, io, &b.in.blob)) {
96                 return NULL;
97         }
98
99         if (io->generic.level == RAW_SFILEINFO_SEC_DESC) {
100                 b.in.flags = io->set_secdesc.in.secinfo_flags;
101         }
102
103         req = smb2_setinfo_send(tree, &b);
104         data_blob_free(&b.in.blob);
105         return req;
106 }
107
108 /*
109   level specific file setinfo call - sync
110 */
111 NTSTATUS smb2_setinfo_file(struct smb2_tree *tree, union smb_setfileinfo *io)
112 {
113         struct smb2_request *req = smb2_setinfo_file_send(tree, io);
114         return smb2_setinfo_recv(req);
115 }