misc: mark winreg_Data little-endian except for a REG_DWORD_BIG_ENDIAN.
[Samba/gbeck.git] / source4 / libcli / raw / rawioctl.c
blob77c7b03f152aa21a1baadfe66a16ce4a3cbbf223
1 /*
2 Unix SMB/CIFS implementation.
3 client file operations
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
25 #define SETUP_REQUEST(cmd, wct, buflen) do { \
26 req = smbcli_request_setup(tree, cmd, wct, buflen); \
27 if (!req) return NULL; \
28 } while (0)
30 /*
31 send a raw smb ioctl - async send
33 static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree,
34 union smb_ioctl *parms)
36 struct smbcli_request *req;
38 SETUP_REQUEST(SMBioctl, 3, 0);
40 SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.file.fnum);
41 SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request);
43 if (!smbcli_request_send(req)) {
44 smbcli_request_destroy(req);
45 return NULL;
48 return req;
51 /*
52 send a raw smb ioctl - async recv
54 static NTSTATUS smb_raw_smbioctl_recv(struct smbcli_request *req,
55 TALLOC_CTX *mem_ctx,
56 union smb_ioctl *parms)
58 if (!smbcli_request_receive(req) ||
59 smbcli_request_is_error(req)) {
60 return smbcli_request_destroy(req);
63 parms->ioctl.out.blob = smbcli_req_pull_blob(&req->in.bufinfo, mem_ctx, req->in.data, -1);
64 return smbcli_request_destroy(req);
69 /****************************************************************************
70 NT ioctl (async send)
71 ****************************************************************************/
72 static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree,
73 union smb_ioctl *parms)
75 struct smb_nttrans nt;
76 uint8_t setup[8];
78 nt.in.max_setup = 4;
79 nt.in.max_param = 0;
80 nt.in.max_data = parms->ntioctl.in.max_data;
81 nt.in.setup_count = 4;
82 nt.in.setup = setup;
83 SIVAL(setup, 0, parms->ntioctl.in.function);
84 SSVAL(setup, 4, parms->ntioctl.in.file.fnum);
85 SCVAL(setup, 6, parms->ntioctl.in.fsctl);
86 SCVAL(setup, 7, parms->ntioctl.in.filter);
87 nt.in.function = NT_TRANSACT_IOCTL;
88 nt.in.params = data_blob(NULL, 0);
89 nt.in.data = parms->ntioctl.in.blob;
91 return smb_raw_nttrans_send(tree, &nt);
94 /****************************************************************************
95 NT ioctl (async recv)
96 ****************************************************************************/
97 static NTSTATUS smb_raw_ntioctl_recv(struct smbcli_request *req,
98 TALLOC_CTX *mem_ctx,
99 union smb_ioctl *parms)
101 NTSTATUS status;
102 struct smb_nttrans nt;
103 TALLOC_CTX *tmp_mem;
105 tmp_mem = talloc_new(mem_ctx);
106 NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
108 status = smb_raw_nttrans_recv(req, tmp_mem, &nt);
109 if (!NT_STATUS_IS_OK(status)) goto fail;
111 parms->ntioctl.out.blob = nt.out.data;
112 talloc_steal(mem_ctx, parms->ntioctl.out.blob.data);
114 fail:
115 talloc_free(tmp_mem);
116 return status;
121 send a raw ioctl - async send
123 struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms)
125 struct smbcli_request *req = NULL;
127 switch (parms->generic.level) {
128 case RAW_IOCTL_IOCTL:
129 req = smb_raw_smbioctl_send(tree, parms);
130 break;
132 case RAW_IOCTL_NTIOCTL:
133 req = smb_raw_ntioctl_send(tree, parms);
134 break;
136 case RAW_IOCTL_SMB2:
137 case RAW_IOCTL_SMB2_NO_HANDLE:
138 return NULL;
141 return req;
145 recv a raw ioctl - async recv
147 NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req,
148 TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
150 switch (parms->generic.level) {
151 case RAW_IOCTL_IOCTL:
152 return smb_raw_smbioctl_recv(req, mem_ctx, parms);
154 case RAW_IOCTL_NTIOCTL:
155 return smb_raw_ntioctl_recv(req, mem_ctx, parms);
157 case RAW_IOCTL_SMB2:
158 case RAW_IOCTL_SMB2_NO_HANDLE:
159 break;
161 return NT_STATUS_INVALID_LEVEL;
165 send a raw ioctl - sync interface
167 NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree,
168 TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
170 struct smbcli_request *req;
171 req = smb_raw_ioctl_send(tree, parms);
172 return smb_raw_ioctl_recv(req, mem_ctx, parms);