r23792: convert Samba4 to GPLv3
[samba.git] / source4 / libcli / clitrans2.c
1 /* 
2    Unix SMB/CIFS implementation.
3    client trans2 calls
4    Copyright (C) James J Myers 2003     <myersjj@samba.org>
5    
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.
10    
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.
15    
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/>.
18 */
19
20 #include "includes.h"
21 #include "libcli/raw/libcliraw.h"
22
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)
29 {
30         union smb_fileinfo parms;
31         TALLOC_CTX *mem_ctx;
32         NTSTATUS status;
33
34         mem_ctx = talloc_init("smbcli_qpathinfo");
35         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
36
37         parms.standard.level = RAW_FILEINFO_STANDARD;
38         parms.standard.in.file.path = fname;
39
40         status = smb_raw_pathinfo(tree, mem_ctx, &parms);
41         talloc_free(mem_ctx);
42         if (!NT_STATUS_IS_OK(status))
43                 return status;
44
45         if (c_time) {
46                 *c_time = parms.standard.out.create_time;
47         }
48         if (a_time) {
49                 *a_time = parms.standard.out.access_time;
50         }
51         if (m_time) {
52                 *m_time = parms.standard.out.write_time;
53         }
54         if (size) {
55                 *size = parms.standard.out.size;
56         }
57         if (mode) {
58                 *mode = parms.standard.out.attrib;
59         }
60
61         return status;
62 }
63
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)
71 {
72         union smb_fileinfo parms;
73         TALLOC_CTX *mem_ctx;
74         NTSTATUS status;
75
76         mem_ctx = talloc_init("smbcli_qfilename");
77         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
78
79         parms.all_info.level = RAW_FILEINFO_ALL_INFO;
80         parms.all_info.in.file.path = fname;
81
82         status = smb_raw_pathinfo(tree, mem_ctx, &parms);
83         talloc_free(mem_ctx);
84         if (!NT_STATUS_IS_OK(status))
85                 return status;
86
87         if (c_time) {
88                 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
89         }
90         if (a_time) {
91                 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
92         }
93         if (m_time) {
94                 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
95         }
96         if (w_time) {
97                 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
98         }
99         if (size) {
100                 *size = parms.all_info.out.size;
101         }
102         if (mode) {
103                 *mode = parms.all_info.out.attrib;
104         }
105
106         return status;
107 }
108
109
110 /****************************************************************************
111 send a qfileinfo QUERY_FILE_NAME_INFO call
112 ****************************************************************************/
113 NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name)
114 {
115         union smb_fileinfo parms;
116         TALLOC_CTX *mem_ctx;
117         NTSTATUS status;
118
119         mem_ctx = talloc_init("smbcli_qfilename");
120         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
121
122         parms.name_info.level = RAW_FILEINFO_NAME_INFO;
123         parms.name_info.in.file.fnum = fnum;
124
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;
130         }
131
132         *name = strdup(parms.name_info.out.fname.s);
133
134         talloc_free(mem_ctx);
135
136         return status;
137 }
138
139
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)
147 {
148         union smb_fileinfo parms;
149         TALLOC_CTX *mem_ctx;
150         NTSTATUS status;
151
152         mem_ctx = talloc_init("smbcli_qfileinfo");
153         if (!mem_ctx) 
154                 return NT_STATUS_NO_MEMORY;
155
156         parms.all_info.level = RAW_FILEINFO_ALL_INFO;
157         parms.all_info.in.file.fnum = fnum;
158
159         status = smb_raw_fileinfo(tree, mem_ctx, &parms);
160         talloc_free(mem_ctx);
161         if (!NT_STATUS_IS_OK(status)) {
162                 return status;
163         }
164
165         if (c_time) {
166                 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
167         }
168         if (a_time) {
169                 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
170         }
171         if (m_time) {
172                 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
173         }
174         if (w_time) {
175                 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
176         }
177         if (mode) {
178                 *mode = parms.all_info.out.attrib;
179         }
180         if (size) {
181                 *size = (size_t)parms.all_info.out.size;
182         }
183         if (ino) {
184                 *ino = 0;
185         }
186
187         return status;
188 }
189
190
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)
196 {
197         union smb_fileinfo parms;
198         TALLOC_CTX *mem_ctx;
199         NTSTATUS status;
200
201         parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
202         parms.alt_name_info.in.file.path = fname;
203
204         mem_ctx = talloc_init("smbcli_qpathinfo_alt_name");
205         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
206
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);
212         }
213
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);
218         }
219
220         talloc_free(mem_ctx);
221
222         return NT_STATUS_OK;
223 }