summaryrefslogtreecommitdiff
path: root/source4/libcli/clitrans2.c
blob: f8699e0191a6c9ef6228a67009ff56850374e51e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* 
   Unix SMB/CIFS implementation.
   client trans2 calls
   Copyright (C) James J Myers 2003	<myersjj@samba.org>
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "libcli/raw/libcliraw.h"

/****************************************************************************
send a qpathinfo call
****************************************************************************/
NTSTATUS smbcli_qpathinfo(struct smbcli_tree *tree, const char *fname, 
		       time_t *c_time, time_t *a_time, time_t *m_time, 
		       size_t *size, uint16_t *mode)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("smbcli_qpathinfo");
	if (!mem_ctx) return NT_STATUS_NO_MEMORY;

	parms.standard.level = RAW_FILEINFO_STANDARD;
	parms.standard.file.path = fname;

	status = smb_raw_pathinfo(tree, mem_ctx, &parms);
	talloc_free(mem_ctx);
	if (!NT_STATUS_IS_OK(status))
		return status;

	if (c_time) {
		*c_time = parms.standard.out.create_time;
	}
	if (a_time) {
		*a_time = parms.standard.out.access_time;
	}
	if (m_time) {
		*m_time = parms.standard.out.write_time;
	}
	if (size) {
		*size = parms.standard.out.size;
	}
	if (mode) {
		*mode = parms.standard.out.attrib;
	}

	return status;
}

/****************************************************************************
send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
****************************************************************************/
NTSTATUS smbcli_qpathinfo2(struct smbcli_tree *tree, const char *fname, 
			time_t *c_time, time_t *a_time, time_t *m_time, 
			time_t *w_time, size_t *size, uint16_t *mode,
			ino_t *ino)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("smbcli_qfilename");
	if (!mem_ctx) return NT_STATUS_NO_MEMORY;

	parms.all_info.level = RAW_FILEINFO_ALL_INFO;
	parms.all_info.file.path = fname;

	status = smb_raw_pathinfo(tree, mem_ctx, &parms);
	talloc_free(mem_ctx);
	if (!NT_STATUS_IS_OK(status))
		return status;

	if (c_time) {
		*c_time = nt_time_to_unix(parms.all_info.out.create_time);
	}
	if (a_time) {
		*a_time = nt_time_to_unix(parms.all_info.out.access_time);
	}
	if (m_time) {
		*m_time = nt_time_to_unix(parms.all_info.out.change_time);
	}
	if (w_time) {
		*w_time = nt_time_to_unix(parms.all_info.out.write_time);
	}
	if (size) {
		*size = parms.all_info.out.size;
	}
	if (mode) {
		*mode = parms.all_info.out.attrib;
	}

	return status;
}


/****************************************************************************
send a qfileinfo QUERY_FILE_NAME_INFO call
****************************************************************************/
NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("smbcli_qfilename");
	if (!mem_ctx) return NT_STATUS_NO_MEMORY;

	parms.name_info.level = RAW_FILEINFO_NAME_INFO;
	parms.name_info.file.fnum = fnum;

	status = smb_raw_fileinfo(tree, mem_ctx, &parms);
	if (!NT_STATUS_IS_OK(status)) {
		talloc_free(mem_ctx);
		*name = NULL;
		return status;
	}

	*name = strdup(parms.name_info.out.fname.s);

	talloc_free(mem_ctx);

	return status;
}


/****************************************************************************
send a qfileinfo call
****************************************************************************/
NTSTATUS smbcli_qfileinfo(struct smbcli_tree *tree, int fnum, 
		       uint16_t *mode, size_t *size,
		       time_t *c_time, time_t *a_time, time_t *m_time, 
		       time_t *w_time, ino_t *ino)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("smbcli_qfileinfo");
	if (!mem_ctx) 
		return NT_STATUS_NO_MEMORY;

	parms.all_info.level = RAW_FILEINFO_ALL_INFO;
	parms.all_info.file.fnum = fnum;

	status = smb_raw_fileinfo(tree, mem_ctx, &parms);
	talloc_free(mem_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (c_time) {
		*c_time = nt_time_to_unix(parms.all_info.out.create_time);
	}
	if (a_time) {
		*a_time = nt_time_to_unix(parms.all_info.out.access_time);
	}
	if (m_time) {
		*m_time = nt_time_to_unix(parms.all_info.out.change_time);
	}
	if (w_time) {
		*w_time = nt_time_to_unix(parms.all_info.out.write_time);
	}
	if (mode) {
		*mode = parms.all_info.out.attrib;
	}
	if (size) {
		*size = (size_t)parms.all_info.out.size;
	}
	if (ino) {
		*ino = 0;
	}

	return status;
}


/****************************************************************************
send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
****************************************************************************/
NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname, 
				const char **alt_name)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
	parms.alt_name_info.file.path = fname;

	mem_ctx = talloc_init("smbcli_qpathinfo_alt_name");
	if (!mem_ctx) return NT_STATUS_NO_MEMORY;

	status = smb_raw_pathinfo(tree, mem_ctx, &parms);
	if (!NT_STATUS_IS_OK(status)) {
		talloc_free(mem_ctx);
		*alt_name = NULL;
		return smbcli_nt_error(tree);
	}

	if (!parms.alt_name_info.out.fname.s) {
		*alt_name = strdup("");
	} else {
		*alt_name = strdup(parms.alt_name_info.out.fname.s);
	}

	talloc_free(mem_ctx);

	return NT_STATUS_OK;
}