summaryrefslogtreecommitdiff
path: root/source4/libcli/clitrans2.c
blob: 6fd5c2ce288f4988357442074a0173c61905353d (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
/* 
   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"

/****************************************************************************
send a qpathinfo call
****************************************************************************/
BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, 
		   time_t *c_time, time_t *a_time, time_t *m_time, 
		   size_t *size, uint16 *mode)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("cli_qpathinfo");
	if (!mem_ctx) return False;

	parms.standard.level = RAW_FILEINFO_STANDARD;
	parms.standard.in.fname = fname;

	status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
	talloc_destroy(mem_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		return False;
	}

	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 True;
}

/****************************************************************************
send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
****************************************************************************/
BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, 
		    time_t *c_time, time_t *a_time, time_t *m_time, 
		    time_t *w_time, size_t *size, uint16 *mode,
		    SMB_INO_T *ino)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("cli_qfilename");
	if (!mem_ctx) return False;

	parms.all_info.level = RAW_FILEINFO_ALL_INFO;
	parms.all_info.in.fname = fname;

	status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
	talloc_destroy(mem_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		return False;
	}

	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 True;
}


/****************************************************************************
send a qfileinfo QUERY_FILE_NAME_INFO call
****************************************************************************/
BOOL cli_qfilename(struct cli_state *cli, int fnum, 
		   const char **name)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("cli_qfilename");
	if (!mem_ctx) return False;

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

	status = smb_raw_fileinfo(cli->tree, mem_ctx, &parms);
	if (!NT_STATUS_IS_OK(status)) {
		talloc_destroy(mem_ctx);
		*name = NULL;
		return False;
	}

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

	talloc_destroy(mem_ctx);

	return True;
}


/****************************************************************************
send a qfileinfo call
****************************************************************************/
BOOL cli_qfileinfo(struct cli_state *cli, int fnum, 
		   uint16 *mode, size_t *size,
		   time_t *c_time, time_t *a_time, time_t *m_time, 
		   time_t *w_time, SMB_INO_T *ino)
{
	union smb_fileinfo parms;
	TALLOC_CTX *mem_ctx;
	NTSTATUS status;

	mem_ctx = talloc_init("cli_qfileinfo");
	if (!mem_ctx) return False;

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

	status = smb_raw_fileinfo(cli->tree, mem_ctx, &parms);
	talloc_destroy(mem_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		return False;
	}

	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 True;
}


/****************************************************************************
send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
****************************************************************************/
NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, 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.in.fname = fname;

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

	status = smb_raw_pathinfo(cli->tree, mem_ctx, &parms);
	if (!NT_STATUS_IS_OK(status)) {
		talloc_destroy(mem_ctx);
		*alt_name = NULL;
		return cli_nt_error(cli);
	}

	*alt_name = strdup(parms.alt_name_info.out.fname.s);

	talloc_destroy(mem_ctx);

	return NT_STATUS_OK;
}