r9022: One more step in the game of whack-a-mole with the PAC.
[Samba/gbeck.git] / source4 / libcli / clitrans2.c
blob6be92fa17d6b8221c9bcaef2d809342db190c01e
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 /****************************************************************************
24 send a qpathinfo call
25 ****************************************************************************/
26 NTSTATUS smbcli_qpathinfo(struct smbcli_tree *tree, const char *fname,
27 time_t *c_time, time_t *a_time, time_t *m_time,
28 size_t *size, uint16_t *mode)
30 union smb_fileinfo parms;
31 TALLOC_CTX *mem_ctx;
32 NTSTATUS status;
34 mem_ctx = talloc_init("smbcli_qpathinfo");
35 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
37 parms.standard.level = RAW_FILEINFO_STANDARD;
38 parms.standard.in.fname = fname;
40 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
41 talloc_free(mem_ctx);
42 if (!NT_STATUS_IS_OK(status))
43 return status;
45 if (c_time) {
46 *c_time = parms.standard.out.create_time;
48 if (a_time) {
49 *a_time = parms.standard.out.access_time;
51 if (m_time) {
52 *m_time = parms.standard.out.write_time;
54 if (size) {
55 *size = parms.standard.out.size;
57 if (mode) {
58 *mode = parms.standard.out.attrib;
61 return status;
64 /****************************************************************************
65 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
66 ****************************************************************************/
67 NTSTATUS smbcli_qpathinfo2(struct smbcli_tree *tree, const char *fname,
68 time_t *c_time, time_t *a_time, time_t *m_time,
69 time_t *w_time, size_t *size, uint16_t *mode,
70 ino_t *ino)
72 union smb_fileinfo parms;
73 TALLOC_CTX *mem_ctx;
74 NTSTATUS status;
76 mem_ctx = talloc_init("smbcli_qfilename");
77 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
79 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
80 parms.all_info.in.fname = fname;
82 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
83 talloc_free(mem_ctx);
84 if (!NT_STATUS_IS_OK(status))
85 return status;
87 if (c_time) {
88 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
90 if (a_time) {
91 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
93 if (m_time) {
94 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
96 if (w_time) {
97 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
99 if (size) {
100 *size = parms.all_info.out.size;
102 if (mode) {
103 *mode = parms.all_info.out.attrib;
106 return status;
110 /****************************************************************************
111 send a qfileinfo QUERY_FILE_NAME_INFO call
112 ****************************************************************************/
113 NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name)
115 union smb_fileinfo parms;
116 TALLOC_CTX *mem_ctx;
117 NTSTATUS status;
119 mem_ctx = talloc_init("smbcli_qfilename");
120 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
122 parms.name_info.level = RAW_FILEINFO_NAME_INFO;
123 parms.name_info.in.fnum = fnum;
125 status = smb_raw_fileinfo(tree, mem_ctx, &parms);
126 if (!NT_STATUS_IS_OK(status)) {
127 talloc_free(mem_ctx);
128 *name = NULL;
129 return status;
132 *name = strdup(parms.name_info.out.fname.s);
134 talloc_free(mem_ctx);
136 return status;
140 /****************************************************************************
141 send a qfileinfo call
142 ****************************************************************************/
143 NTSTATUS smbcli_qfileinfo(struct smbcli_tree *tree, int fnum,
144 uint16_t *mode, size_t *size,
145 time_t *c_time, time_t *a_time, time_t *m_time,
146 time_t *w_time, ino_t *ino)
148 union smb_fileinfo parms;
149 TALLOC_CTX *mem_ctx;
150 NTSTATUS status;
152 mem_ctx = talloc_init("smbcli_qfileinfo");
153 if (!mem_ctx)
154 return NT_STATUS_NO_MEMORY;
156 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
157 parms.all_info.in.fnum = fnum;
159 status = smb_raw_fileinfo(tree, mem_ctx, &parms);
160 talloc_free(mem_ctx);
161 if (!NT_STATUS_IS_OK(status)) {
162 return status;
165 if (c_time) {
166 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
168 if (a_time) {
169 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
171 if (m_time) {
172 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
174 if (w_time) {
175 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
177 if (mode) {
178 *mode = parms.all_info.out.attrib;
180 if (size) {
181 *size = (size_t)parms.all_info.out.size;
183 if (ino) {
184 *ino = 0;
187 return status;
191 /****************************************************************************
192 send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
193 ****************************************************************************/
194 NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname,
195 const char **alt_name)
197 union smb_fileinfo parms;
198 TALLOC_CTX *mem_ctx;
199 NTSTATUS status;
201 parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
202 parms.alt_name_info.in.fname = fname;
204 mem_ctx = talloc_init("smbcli_qpathinfo_alt_name");
205 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
207 status = smb_raw_pathinfo(tree, mem_ctx, &parms);
208 if (!NT_STATUS_IS_OK(status)) {
209 talloc_free(mem_ctx);
210 *alt_name = NULL;
211 return smbcli_nt_error(tree);
214 if (!parms.alt_name_info.out.fname.s) {
215 *alt_name = strdup("");
216 } else {
217 *alt_name = strdup(parms.alt_name_info.out.fname.s);
220 talloc_free(mem_ctx);
222 return NT_STATUS_OK;