don't dereference null pointer
[Samba/gebeck_regimport.git] / source4 / libcli / clitrans2.c
blob0ceac925f73c50e8c8b5baa723c39174fa655fcd
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 BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
27 time_t *c_time, time_t *a_time, time_t *m_time,
28 size_t *size, uint16 *mode)
30 union smb_fileinfo parms;
31 TALLOC_CTX *mem_ctx;
32 NTSTATUS status;
34 mem_ctx = talloc_init("cli_qpathinfo");
35 if (!mem_ctx) return False;
37 parms.standard.level = RAW_FILEINFO_STANDARD;
38 parms.standard.in.fname = fname;
40 status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
41 talloc_destroy(mem_ctx);
42 if (!NT_STATUS_IS_OK(status)) {
43 return False;
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 True;
65 /****************************************************************************
66 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
67 ****************************************************************************/
68 BOOL cli_qpathinfo2(struct cli_state *cli, 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 *mode,
71 SMB_INO_T *ino)
73 union smb_fileinfo parms;
74 TALLOC_CTX *mem_ctx;
75 NTSTATUS status;
77 mem_ctx = talloc_init("cli_qfilename");
78 if (!mem_ctx) return False;
80 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
81 parms.all_info.in.fname = fname;
83 status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
84 talloc_destroy(mem_ctx);
85 if (!NT_STATUS_IS_OK(status)) {
86 return False;
89 if (c_time) {
90 *c_time = nt_time_to_unix(&parms.all_info.out.create_time);
92 if (a_time) {
93 *a_time = nt_time_to_unix(&parms.all_info.out.access_time);
95 if (m_time) {
96 *m_time = nt_time_to_unix(&parms.all_info.out.change_time);
98 if (w_time) {
99 *w_time = nt_time_to_unix(&parms.all_info.out.write_time);
101 if (size) {
102 *size = parms.all_info.out.size;
104 if (mode) {
105 *mode = parms.all_info.out.attrib;
108 return True;
112 /****************************************************************************
113 send a qfileinfo QUERY_FILE_NAME_INFO call
114 ****************************************************************************/
115 BOOL cli_qfilename(struct cli_state *cli, int fnum,
116 const char **name)
118 union smb_fileinfo parms;
119 TALLOC_CTX *mem_ctx;
120 NTSTATUS status;
122 mem_ctx = talloc_init("cli_qfilename");
123 if (!mem_ctx) return False;
125 parms.name_info.level = RAW_FILEINFO_NAME_INFO;
126 parms.name_info.in.fnum = fnum;
128 status = smb_raw_fileinfo(cli->tree, mem_ctx, &parms);
129 if (!NT_STATUS_IS_OK(status)) {
130 talloc_destroy(mem_ctx);
131 *name = NULL;
132 return False;
135 *name = strdup(parms.name_info.out.fname.s);
137 talloc_destroy(mem_ctx);
139 return True;
143 /****************************************************************************
144 send a qfileinfo call
145 ****************************************************************************/
146 BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
147 uint16 *mode, size_t *size,
148 time_t *c_time, time_t *a_time, time_t *m_time,
149 time_t *w_time, SMB_INO_T *ino)
151 union smb_fileinfo parms;
152 TALLOC_CTX *mem_ctx;
153 NTSTATUS status;
155 mem_ctx = talloc_init("cli_qfileinfo");
156 if (!mem_ctx) return False;
158 parms.all_info.level = RAW_FILEINFO_ALL_INFO;
159 parms.all_info.in.fnum = fnum;
161 status = smb_raw_fileinfo(cli->tree, mem_ctx, &parms);
162 talloc_destroy(mem_ctx);
163 if (!NT_STATUS_IS_OK(status)) {
164 return False;
167 if (c_time) {
168 *c_time = nt_time_to_unix(&parms.all_info.out.create_time);
170 if (a_time) {
171 *a_time = nt_time_to_unix(&parms.all_info.out.access_time);
173 if (m_time) {
174 *m_time = nt_time_to_unix(&parms.all_info.out.change_time);
176 if (w_time) {
177 *w_time = nt_time_to_unix(&parms.all_info.out.write_time);
179 if (mode) {
180 *mode = parms.all_info.out.attrib;
182 if (size) {
183 *size = (size_t)parms.all_info.out.size;
185 if (ino) {
186 *ino = 0;
189 return True;
193 /****************************************************************************
194 send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
195 ****************************************************************************/
196 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname,
197 const char **alt_name)
199 union smb_fileinfo parms;
200 TALLOC_CTX *mem_ctx;
201 NTSTATUS status;
203 parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
204 parms.alt_name_info.in.fname = fname;
206 mem_ctx = talloc_init("cli_qpathinfo_alt_name");
207 if (!mem_ctx) return NT_STATUS_NO_MEMORY;
209 status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
210 if (!NT_STATUS_IS_OK(status)) {
211 talloc_destroy(mem_ctx);
212 *alt_name = NULL;
213 return cli_nt_error(cli);
216 if (!parms.alt_name_info.out.fname.s) {
217 *alt_name = strdup("");
218 } else {
219 *alt_name = strdup(parms.alt_name_info.out.fname.s);
222 talloc_destroy(mem_ctx);
224 return NT_STATUS_OK;