ctdb-tests: Handle interactions with monitor events
[Samba.git] / source4 / libcli / clitrans2.c
blob5c5ba6585f6eb1e287678ca544b222ba3ec40134
1 /*
2 Unix SMB/CIFS implementation.
3 client trans2 calls
4 Copyright (C) James J Myers 2003 <myersjj@samba.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "libcli/raw/libcliraw.h"
22 #include "libcli/libcli.h"
24 /****************************************************************************
25 send a qpathinfo call
26 ****************************************************************************/
27 NTSTATUS smbcli_qpathinfo(struct smbcli_tree *tree, const char *fname,
28 time_t *c_time, time_t *a_time, time_t *m_time,
29 size_t *size, uint16_t *mode)
31 union smb_fileinfo parms;
32 TALLOC_CTX *mem_ctx;
33 NTSTATUS status;
35 mem_ctx = talloc_init("smbcli_qpathinfo");
36 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
38 parms.standard.level = RAW_FILEINFO_STANDARD;
39 parms.standard.in.file.path = fname;
41 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
42 talloc_free(mem_ctx);
43 if (!NT_STATUS_IS_OK(status))
44 return status;
46 if (c_time) {
47 *c_time = parms.standard.out.create_time;
49 if (a_time) {
50 *a_time = parms.standard.out.access_time;
52 if (m_time) {
53 *m_time = parms.standard.out.write_time;
55 if (size) {
56 *size = parms.standard.out.size;
58 if (mode) {
59 *mode = parms.standard.out.attrib;
62 return status;
65 /****************************************************************************
66 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
67 ****************************************************************************/
68 NTSTATUS smbcli_qpathinfo2(struct smbcli_tree *tree, const char *fname,
69 time_t *c_time, time_t *a_time, time_t *m_time,
70 time_t *w_time, size_t *size, uint16_t *mode,
71 ino_t *ino)
73 union smb_fileinfo parms;
74 TALLOC_CTX *mem_ctx;
75 NTSTATUS status;
77 mem_ctx = talloc_init("smbcli_qfilename");
78 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
80 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
81 parms.all_info.in.file.path = fname;
83 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
84 talloc_free(mem_ctx);
85 if (!NT_STATUS_IS_OK(status))
86 return status;
88 if (c_time) {
89 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
91 if (a_time) {
92 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
94 if (m_time) {
95 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
97 if (w_time) {
98 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
100 if (size) {
101 *size = parms.all_info.out.size;
103 if (mode) {
104 *mode = parms.all_info.out.attrib;
107 return status;
111 /****************************************************************************
112 send a qfileinfo QUERY_FILE_NAME_INFO call
113 ****************************************************************************/
114 NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name)
116 union smb_fileinfo parms;
117 TALLOC_CTX *mem_ctx;
118 NTSTATUS status;
120 mem_ctx = talloc_init("smbcli_qfilename");
121 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
123 parms.name_info.level = RAW_FILEINFO_NAME_INFO;
124 parms.name_info.in.file.fnum = fnum;
126 status = smb_raw_fileinfo(tree, mem_ctx, &parms);
127 if (!NT_STATUS_IS_OK(status)) {
128 talloc_free(mem_ctx);
129 *name = NULL;
130 return status;
133 *name = strdup(parms.name_info.out.fname.s);
135 talloc_free(mem_ctx);
137 return status;
141 /****************************************************************************
142 send a qfileinfo call
143 ****************************************************************************/
144 NTSTATUS smbcli_qfileinfo(struct smbcli_tree *tree, int fnum,
145 uint16_t *mode, size_t *size,
146 time_t *c_time, time_t *a_time, time_t *m_time,
147 time_t *w_time, ino_t *ino)
149 union smb_fileinfo parms;
150 TALLOC_CTX *mem_ctx;
151 NTSTATUS status;
153 mem_ctx = talloc_init("smbcli_qfileinfo");
154 if (!mem_ctx)
155 return NT_STATUS_NO_MEMORY;
157 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
158 parms.all_info.in.file.fnum = fnum;
160 status = smb_raw_fileinfo(tree, mem_ctx, &parms);
161 talloc_free(mem_ctx);
162 if (!NT_STATUS_IS_OK(status)) {
163 return status;
166 if (c_time) {
167 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
169 if (a_time) {
170 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
172 if (m_time) {
173 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
175 if (w_time) {
176 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
178 if (mode) {
179 *mode = parms.all_info.out.attrib;
181 if (size) {
182 *size = (size_t)parms.all_info.out.size;
184 if (ino) {
185 *ino = 0;
188 return status;
192 /****************************************************************************
193 send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
194 ****************************************************************************/
195 NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname,
196 const char **alt_name)
198 union smb_fileinfo parms;
199 TALLOC_CTX *mem_ctx;
200 NTSTATUS status;
202 parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
203 parms.alt_name_info.in.file.path = fname;
205 mem_ctx = talloc_init("smbcli_qpathinfo_alt_name");
206 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
208 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
209 if (!NT_STATUS_IS_OK(status)) {
210 talloc_free(mem_ctx);
211 *alt_name = NULL;
212 return smbcli_nt_error(tree);
215 if (!parms.alt_name_info.out.fname.s) {
216 *alt_name = strdup("");
217 } else {
218 *alt_name = strdup(parms.alt_name_info.out.fname.s);
221 talloc_free(mem_ctx);
223 return NT_STATUS_OK;