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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/*
Unix SMB/CIFS implementation.
SMB parameters and setup
Copyright (C) Andrew Tridgell 2004
Copyright (C) James 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LIBCLI_H__
#define __LIBCLI_H__
#include "librpc/gen_ndr/nbt.h"
#include "libcli/raw/libcliraw.h"
struct substitute_context;
/*
smbcli_state: internal state used in libcli library for single-threaded callers,
i.e. a single session on a single socket.
*/
struct smbcli_state {
struct smbcli_options options;
struct smbcli_socket *sock; /* NULL if connected */
struct smbcli_transport *transport;
struct smbcli_session *session;
struct smbcli_tree *tree;
struct substitute_context *substitute;
struct smblsa_state *lsa;
};
struct clilist_file_info {
uint64_t size;
uint16_t attrib;
time_t mtime;
const char *name;
const char *short_name;
};
struct nbt_dc_name {
const char *address;
const char *name;
};
struct cli_credentials;
struct tevent_context;
/* passed to br lock code. */
enum brl_type {
READ_LOCK,
WRITE_LOCK,
PENDING_READ_LOCK,
PENDING_WRITE_LOCK
};
#include "libcli/raw/libcliraw.h"
struct gensec_settings;
ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, void *_buf, off_t offset, size_t size);
/****************************************************************************
write to a file
write_mode: 0x0001 disallow write caching
0x0002 return bytes remaining
0x0004 use raw named pipe protocol
0x0008 start of message mode named pipe protocol
****************************************************************************/
ssize_t smbcli_write(struct smbcli_tree *tree,
int fnum, uint16_t write_mode,
const void *_buf, off_t offset, size_t size);
/****************************************************************************
write to a file using a SMBwrite and not bypassing 0 byte writes
****************************************************************************/
ssize_t smbcli_smbwrite(struct smbcli_tree *tree,
int fnum, const void *_buf, off_t offset, size_t size1);
bool smbcli_socket_connect(struct smbcli_state *cli, const char *server,
const char **ports,
struct tevent_context *ev_ctx,
struct resolve_context *resolve_ctx,
struct smbcli_options *options,
const char *socket_options,
struct nbt_name *calling,
struct nbt_name *called);
NTSTATUS smbcli_negprot(struct smbcli_state *cli, bool unicode, int maxprotocol);
NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
struct cli_credentials *credentials,
const char *workgroup,
struct smbcli_session_options options,
struct gensec_settings *gensec_settings);
NTSTATUS smbcli_tconX(struct smbcli_state *cli, const char *sharename,
const char *devtype, const char *password);
NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx,
struct smbcli_state **ret_cli,
const char *host,
const char **ports,
const char *sharename,
const char *devtype,
const char *socket_options,
struct cli_credentials *credentials,
struct resolve_context *resolve_ctx,
struct tevent_context *ev,
struct smbcli_options *options,
struct smbcli_session_options *session_options,
struct gensec_settings *gensec_settings);
NTSTATUS smbcli_tdis(struct smbcli_state *cli);
/****************************************************************************
Initialise a client state structure.
****************************************************************************/
struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx);
bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
char **hostname, char **sharename);
/****************************************************************************
Symlink a file (UNIX extensions).
****************************************************************************/
NTSTATUS smbcli_unix_symlink(struct smbcli_tree *tree, const char *fname_src,
const char *fname_dst);
/****************************************************************************
Hard a file (UNIX extensions).
****************************************************************************/
NTSTATUS smbcli_unix_hardlink(struct smbcli_tree *tree, const char *fname_src,
const char *fname_dst);
/****************************************************************************
chmod a file (UNIX extensions).
****************************************************************************/
NTSTATUS smbcli_unix_chmod(struct smbcli_tree *tree, const char *fname, mode_t mode);
/****************************************************************************
chown a file (UNIX extensions).
****************************************************************************/
NTSTATUS smbcli_unix_chown(struct smbcli_tree *tree, const char *fname, uid_t uid,
gid_t gid);
/****************************************************************************
Rename a file.
****************************************************************************/
NTSTATUS smbcli_rename(struct smbcli_tree *tree, const char *fname_src,
const char *fname_dst);
/****************************************************************************
Delete a file.
****************************************************************************/
NTSTATUS smbcli_unlink(struct smbcli_tree *tree, const char *fname);
/****************************************************************************
Delete a wildcard pattern of files.
****************************************************************************/
NTSTATUS smbcli_unlink_wcard(struct smbcli_tree *tree, const char *fname);
/****************************************************************************
Create a directory.
****************************************************************************/
NTSTATUS smbcli_mkdir(struct smbcli_tree *tree, const char *dname);
/****************************************************************************
Remove a directory.
****************************************************************************/
NTSTATUS smbcli_rmdir(struct smbcli_tree *tree, const char *dname);
/****************************************************************************
Set or clear the delete on close flag.
****************************************************************************/
NTSTATUS smbcli_nt_delete_on_close(struct smbcli_tree *tree, int fnum,
bool flag);
/****************************************************************************
Create/open a file - exposing the full horror of the NT API :-).
Used in CIFS-on-CIFS NTVFS.
****************************************************************************/
int smbcli_nt_create_full(struct smbcli_tree *tree, const char *fname,
uint32_t CreatFlags, uint32_t DesiredAccess,
uint32_t FileAttributes, uint32_t ShareAccess,
uint32_t CreateDisposition, uint32_t CreateOptions,
uint8_t SecurityFlags);
/****************************************************************************
Open a file (using SMBopenx)
WARNING: if you open with O_WRONLY then getattrE won't work!
****************************************************************************/
int smbcli_open(struct smbcli_tree *tree, const char *fname, int flags,
int share_mode);
/****************************************************************************
Close a file.
****************************************************************************/
NTSTATUS smbcli_close(struct smbcli_tree *tree, int fnum);
/****************************************************************************
send a lock with a specified locktype
this is used for testing LOCKING_ANDX_CANCEL_LOCK
****************************************************************************/
NTSTATUS smbcli_locktype(struct smbcli_tree *tree, int fnum,
uint32_t offset, uint32_t len, int timeout,
uint8_t locktype);
/****************************************************************************
Lock a file.
****************************************************************************/
NTSTATUS smbcli_lock(struct smbcli_tree *tree, int fnum,
uint32_t offset, uint32_t len, int timeout,
enum brl_type lock_type);
/****************************************************************************
Unlock a file.
****************************************************************************/
NTSTATUS smbcli_unlock(struct smbcli_tree *tree, int fnum, uint32_t offset, uint32_t len);
/****************************************************************************
Lock a file with 64 bit offsets.
****************************************************************************/
NTSTATUS smbcli_lock64(struct smbcli_tree *tree, int fnum,
off_t offset, off_t len, int timeout,
enum brl_type lock_type);
/****************************************************************************
Unlock a file with 64 bit offsets.
****************************************************************************/
NTSTATUS smbcli_unlock64(struct smbcli_tree *tree, int fnum, off_t offset,
off_t len);
/****************************************************************************
Do a SMBgetattrE call.
****************************************************************************/
NTSTATUS smbcli_getattrE(struct smbcli_tree *tree, int fnum,
uint16_t *attr, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time);
/****************************************************************************
Do a SMBgetatr call
****************************************************************************/
NTSTATUS smbcli_getatr(struct smbcli_tree *tree, const char *fname,
uint16_t *attr, size_t *size, time_t *t);
/****************************************************************************
Do a SMBsetatr call.
****************************************************************************/
NTSTATUS smbcli_setatr(struct smbcli_tree *tree, const char *fname, uint16_t mode,
time_t t);
/****************************************************************************
Do a setfileinfo basic_info call.
****************************************************************************/
NTSTATUS smbcli_fsetatr(struct smbcli_tree *tree, int fnum, uint16_t mode,
NTTIME create_time, NTTIME access_time,
NTTIME write_time, NTTIME change_time);
/****************************************************************************
truncate a file to a given size
****************************************************************************/
NTSTATUS smbcli_ftruncate(struct smbcli_tree *tree, int fnum, uint64_t size);
/****************************************************************************
Check for existence of a dir.
****************************************************************************/
NTSTATUS smbcli_chkpath(struct smbcli_tree *tree, const char *path);
/****************************************************************************
Query disk space.
****************************************************************************/
NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, uint32_t *bsize,
uint64_t *total, uint64_t *avail);
/****************************************************************************
Create and open a temporary file.
****************************************************************************/
int smbcli_ctemp(struct smbcli_tree *tree, const char *path, char **tmp_path);
/****************************************************************************
Interpret a long filename structure.
****************************************************************************/
int smbcli_list_new(struct smbcli_tree *tree, const char *Mask, uint16_t attribute,
enum smb_search_data_level level,
void (*fn)(struct clilist_file_info *, const char *, void *),
void *caller_state);
/****************************************************************************
Interpret a short filename structure.
The length of the structure is returned.
****************************************************************************/
int smbcli_list_old(struct smbcli_tree *tree, const char *Mask, uint16_t attribute,
void (*fn)(struct clilist_file_info *, const char *, void *),
void *caller_state);
/****************************************************************************
Do a directory listing, calling fn on each file found.
This auto-switches between old and new style.
****************************************************************************/
int smbcli_list(struct smbcli_tree *tree, const char *Mask,uint16_t attribute,
void (*fn)(struct clilist_file_info *, const char *, void *), void *state);
/****************************************************************************
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);
/****************************************************************************
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);
/****************************************************************************
send a qfileinfo QUERY_FILE_NAME_INFO call
****************************************************************************/
NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name);
/****************************************************************************
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);
/****************************************************************************
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);
/* The following definitions come from ../source4/libcli/climessage.c */
/****************************************************************************
start a message sequence
****************************************************************************/
bool smbcli_message_start(struct smbcli_tree *tree, const char *host, const char *username,
int *grp);
/****************************************************************************
send a message
****************************************************************************/
bool smbcli_message_text(struct smbcli_tree *tree, char *msg, int len, int grp);
/****************************************************************************
end a message
****************************************************************************/
bool smbcli_message_end(struct smbcli_tree *tree, int grp);
int smbcli_deltree(struct smbcli_tree *tree, const char *dname);
#endif /* __LIBCLI_H__ */
|