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 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.
23 /****************************************************************************
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
;
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
);
42 if (!NT_STATUS_IS_OK(status
))
46 *c_time
= parms
.standard
.out
.create_time
;
49 *a_time
= parms
.standard
.out
.access_time
;
52 *m_time
= parms
.standard
.out
.write_time
;
55 *size
= parms
.standard
.out
.size
;
58 *mode
= parms
.standard
.out
.attrib
;
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
,
72 union smb_fileinfo parms
;
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
);
84 if (!NT_STATUS_IS_OK(status
))
88 *c_time
= nt_time_to_unix(parms
.all_info
.out
.create_time
);
91 *a_time
= nt_time_to_unix(parms
.all_info
.out
.access_time
);
94 *m_time
= nt_time_to_unix(parms
.all_info
.out
.change_time
);
97 *w_time
= nt_time_to_unix(parms
.all_info
.out
.write_time
);
100 *size
= parms
.all_info
.out
.size
;
103 *mode
= parms
.all_info
.out
.attrib
;
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
;
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
);
132 *name
= strdup(parms
.name_info
.out
.fname
.s
);
134 talloc_free(mem_ctx
);
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
;
152 mem_ctx
= talloc_init("smbcli_qfileinfo");
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
)) {
166 *c_time
= nt_time_to_unix(parms
.all_info
.out
.create_time
);
169 *a_time
= nt_time_to_unix(parms
.all_info
.out
.access_time
);
172 *m_time
= nt_time_to_unix(parms
.all_info
.out
.change_time
);
175 *w_time
= nt_time_to_unix(parms
.all_info
.out
.write_time
);
178 *mode
= parms
.all_info
.out
.attrib
;
181 *size
= (size_t)parms
.all_info
.out
.size
;
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
;
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
);
211 return smbcli_nt_error(tree
);
214 if (!parms
.alt_name_info
.out
.fname
.s
) {
215 *alt_name
= strdup("");
217 *alt_name
= strdup(parms
.alt_name_info
.out
.fname
.s
);
220 talloc_free(mem_ctx
);