r11681: filled in a few more smb2_create() fields
[bbaumbach/samba-autobuild/.git] / source4 / libcli / smb2 / create.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 client tree handling
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27
28 /*
29   send a create request
30 */
31 struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create *io)
32 {
33         struct smb2_request *req;
34         NTSTATUS status;
35         DATA_BLOB path;
36         uint8_t *ptr;
37
38         status = smb2_string_blob(tree, io->in.fname, &path);
39         if (!NT_STATUS_IS_OK(status)) {
40                 return NULL;
41         }
42
43         req = smb2_request_init_tree(tree, SMB2_OP_CREATE, 0x50 + path.length);
44         if (req == NULL) return NULL;
45
46         SIVAL(req->out.body, 0x00, io->in.unknown1);
47         SIVAL(req->out.body, 0x04, io->in.unknown2);
48         SIVAL(req->out.body, 0x08, io->in.unknown3[0]);
49         SIVAL(req->out.body, 0x0C, io->in.unknown3[1]);
50         SIVAL(req->out.body, 0x10, io->in.unknown3[2]);
51         SIVAL(req->out.body, 0x14, io->in.unknown3[3]);
52         SIVAL(req->out.body, 0x18, io->in.access_mask);
53         SIVAL(req->out.body, 0x1C, io->in.file_attr);
54         SIVAL(req->out.body, 0x20, io->in.share_access);
55         SIVAL(req->out.body, 0x24, io->in.open_disposition);
56         SIVAL(req->out.body, 0x28, io->in.create_options);
57
58         SSVAL(req->out.body, 0x2C, 0x40+0x38); /* offset to fname */
59         SSVAL(req->out.body, 0x2E, path.length);
60         SIVAL(req->out.body, 0x30, 0x40+0x38+path.length); /* offset to 2nd buffer? */
61
62         SIVAL(req->out.body, 0x34, io->in.unknown6);
63
64         memcpy(req->out.body+0x38, path.data, path.length);
65
66         ptr = req->out.body+0x38+path.length;
67
68         SIVAL(ptr, 0x00, io->in.unknown7);
69         SIVAL(ptr, 0x04, io->in.unknown8);
70         SIVAL(ptr, 0x08, io->in.unknown9);
71         SIVAL(ptr, 0x0C, io->in.unknown10);
72         SIVAL(ptr, 0x10, io->in.unknown11);
73
74         data_blob_free(&path);
75
76         smb2_transport_send(req);
77
78         return req;
79 }
80
81
82 /*
83   recv a create reply
84 */
85 NTSTATUS smb2_create_recv(struct smb2_request *req, struct smb2_create *io)
86 {
87         if (!smb2_request_receive(req) || 
88             smb2_request_is_error(req)) {
89                 return smb2_request_destroy(req);
90         }
91
92         if (req->in.body_size < 0x54) {
93                 return NT_STATUS_BUFFER_TOO_SMALL;
94         }
95
96         io->out.unknown1 = IVAL(req->in.body, 0x00);
97         io->out.unknown2 = IVAL(req->in.body, 0x04);
98         io->out.create_time = smbcli_pull_nttime(req->in.body, 0x08);
99         io->out.access_time = smbcli_pull_nttime(req->in.body, 0x10);
100         io->out.write_time  = smbcli_pull_nttime(req->in.body, 0x18);
101         io->out.change_time = smbcli_pull_nttime(req->in.body, 0x20);
102         io->out.alloc_size  = BVAL(req->in.body, 0x28);
103         io->out.size        = BVAL(req->in.body, 0x30);
104         io->out.file_attr   = IVAL(req->in.body, 0x38);
105         io->out.unknown8    = IVAL(req->in.body, 0x3C);
106         io->out.handle.data[0] = BVAL(req->in.body, 0x40);
107         io->out.handle.data[1] = BVAL(req->in.body, 0x48);
108         io->out.unknown10 = IVAL(req->in.body, 0x50);
109
110         return smb2_request_destroy(req);
111 }
112
113 /*
114   sync create request
115 */
116 NTSTATUS smb2_create(struct smb2_tree *tree, struct smb2_create *io)
117 {
118         struct smb2_request *req = smb2_create_send(tree, io);
119         return smb2_create_recv(req, io);
120 }