2 Unix SMB/CIFS implementation.
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/>.
21 #include "libcli/raw/libcliraw.h"
22 #include "libcli/libcli.h"
24 /****************************************************************************
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
;
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
);
43 if (!NT_STATUS_IS_OK(status
))
47 *c_time
= parms
.standard
.out
.create_time
;
50 *a_time
= parms
.standard
.out
.access_time
;
53 *m_time
= parms
.standard
.out
.write_time
;
56 *size
= parms
.standard
.out
.size
;
59 *mode
= parms
.standard
.out
.attrib
;
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
,
73 union smb_fileinfo parms
;
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
);
85 if (!NT_STATUS_IS_OK(status
))
89 *c_time
= nt_time_to_unix(parms
.all_info
.out
.create_time
);
92 *a_time
= nt_time_to_unix(parms
.all_info
.out
.access_time
);
95 *m_time
= nt_time_to_unix(parms
.all_info
.out
.change_time
);
98 *w_time
= nt_time_to_unix(parms
.all_info
.out
.write_time
);
101 *size
= parms
.all_info
.out
.size
;
104 *mode
= parms
.all_info
.out
.attrib
;
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
;
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
);
133 *name
= strdup(parms
.name_info
.out
.fname
.s
);
135 talloc_free(mem_ctx
);
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
;
153 mem_ctx
= talloc_init("smbcli_qfileinfo");
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
)) {
167 *c_time
= nt_time_to_unix(parms
.all_info
.out
.create_time
);
170 *a_time
= nt_time_to_unix(parms
.all_info
.out
.access_time
);
173 *m_time
= nt_time_to_unix(parms
.all_info
.out
.change_time
);
176 *w_time
= nt_time_to_unix(parms
.all_info
.out
.write_time
);
179 *mode
= parms
.all_info
.out
.attrib
;
182 *size
= (size_t)parms
.all_info
.out
.size
;
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
;
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
);
212 return smbcli_nt_error(tree
);
215 if (!parms
.alt_name_info
.out
.fname
.s
) {
216 *alt_name
= strdup("");
218 *alt_name
= strdup(parms
.alt_name_info
.out
.fname
.s
);
221 talloc_free(mem_ctx
);