s4:libcli: move smbcli_transport_establish() logic into smbcli_socket_connect()
[Samba/bjacke.git] / source4 / libcli / libcli.h
blob9f661e3f4ddfe06d63f6939bcc532deaa5ad47a6
1 /*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) James Myers 2003 <myersjj@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef __LIBCLI_H__
22 #define __LIBCLI_H__
24 #include "librpc/gen_ndr/nbt.h"
26 struct substitute_context;
28 /*
29 smbcli_state: internal state used in libcli library for single-threaded callers,
30 i.e. a single session on a single socket.
32 struct smbcli_state {
33 struct smbcli_transport *transport;
34 struct smbcli_session *session;
35 struct smbcli_tree *tree;
36 struct substitute_context *substitute;
37 struct smblsa_state *lsa;
40 struct clilist_file_info {
41 uint64_t size;
42 uint16_t attrib;
43 time_t mtime;
44 const char *name;
45 const char *short_name;
48 struct nbt_dc_name {
49 const char *address;
50 const char *name;
53 struct cli_credentials;
54 struct tevent_context;
56 /* passed to br lock code. */
57 enum brl_type {
58 READ_LOCK,
59 WRITE_LOCK,
60 PENDING_READ_LOCK,
61 PENDING_WRITE_LOCK
64 #include "libcli/raw/libcliraw.h"
65 struct gensec_settings;
67 ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, void *_buf, off_t offset, size_t size);
69 /****************************************************************************
70 write to a file
71 write_mode: 0x0001 disallow write cacheing
72 0x0002 return bytes remaining
73 0x0004 use raw named pipe protocol
74 0x0008 start of message mode named pipe protocol
75 ****************************************************************************/
76 ssize_t smbcli_write(struct smbcli_tree *tree,
77 int fnum, uint16_t write_mode,
78 const void *_buf, off_t offset, size_t size);
80 /****************************************************************************
81 write to a file using a SMBwrite and not bypassing 0 byte writes
82 ****************************************************************************/
83 ssize_t smbcli_smbwrite(struct smbcli_tree *tree,
84 int fnum, const void *_buf, off_t offset, size_t size1);
86 bool smbcli_socket_connect(struct smbcli_state *cli, const char *server,
87 const char **ports,
88 struct tevent_context *ev_ctx,
89 struct resolve_context *resolve_ctx,
90 struct smbcli_options *options,
91 const char *socket_options,
92 struct nbt_name *calling,
93 struct nbt_name *called);
94 NTSTATUS smbcli_negprot(struct smbcli_state *cli, bool unicode, int maxprotocol);
95 NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
96 struct cli_credentials *credentials,
97 const char *workgroup,
98 struct smbcli_session_options options,
99 struct gensec_settings *gensec_settings);
100 NTSTATUS smbcli_tconX(struct smbcli_state *cli, const char *sharename,
101 const char *devtype, const char *password);
102 NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx,
103 struct smbcli_state **ret_cli,
104 const char *host,
105 const char **ports,
106 const char *sharename,
107 const char *devtype,
108 const char *socket_options,
109 struct cli_credentials *credentials,
110 struct resolve_context *resolve_ctx,
111 struct tevent_context *ev,
112 struct smbcli_options *options,
113 struct smbcli_session_options *session_options,
114 struct gensec_settings *gensec_settings);
115 NTSTATUS smbcli_tdis(struct smbcli_state *cli);
117 /****************************************************************************
118 Initialise a client state structure.
119 ****************************************************************************/
120 struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx);
121 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
122 char **hostname, char **sharename);
124 /****************************************************************************
125 Symlink a file (UNIX extensions).
126 ****************************************************************************/
127 NTSTATUS smbcli_unix_symlink(struct smbcli_tree *tree, const char *fname_src,
128 const char *fname_dst);
130 /****************************************************************************
131 Hard a file (UNIX extensions).
132 ****************************************************************************/
133 NTSTATUS smbcli_unix_hardlink(struct smbcli_tree *tree, const char *fname_src,
134 const char *fname_dst);
136 /****************************************************************************
137 chmod a file (UNIX extensions).
138 ****************************************************************************/
139 NTSTATUS smbcli_unix_chmod(struct smbcli_tree *tree, const char *fname, mode_t mode);
141 /****************************************************************************
142 chown a file (UNIX extensions).
143 ****************************************************************************/
144 NTSTATUS smbcli_unix_chown(struct smbcli_tree *tree, const char *fname, uid_t uid,
145 gid_t gid);
147 /****************************************************************************
148 Rename a file.
149 ****************************************************************************/
150 NTSTATUS smbcli_rename(struct smbcli_tree *tree, const char *fname_src,
151 const char *fname_dst);
153 /****************************************************************************
154 Delete a file.
155 ****************************************************************************/
156 NTSTATUS smbcli_unlink(struct smbcli_tree *tree, const char *fname);
158 /****************************************************************************
159 Create a directory.
160 ****************************************************************************/
161 NTSTATUS smbcli_mkdir(struct smbcli_tree *tree, const char *dname);
163 /****************************************************************************
164 Remove a directory.
165 ****************************************************************************/
166 NTSTATUS smbcli_rmdir(struct smbcli_tree *tree, const char *dname);
168 /****************************************************************************
169 Set or clear the delete on close flag.
170 ****************************************************************************/
171 NTSTATUS smbcli_nt_delete_on_close(struct smbcli_tree *tree, int fnum,
172 bool flag);
174 /****************************************************************************
175 Create/open a file - exposing the full horror of the NT API :-).
176 Used in CIFS-on-CIFS NTVFS.
177 ****************************************************************************/
178 int smbcli_nt_create_full(struct smbcli_tree *tree, const char *fname,
179 uint32_t CreatFlags, uint32_t DesiredAccess,
180 uint32_t FileAttributes, uint32_t ShareAccess,
181 uint32_t CreateDisposition, uint32_t CreateOptions,
182 uint8_t SecurityFlags);
184 /****************************************************************************
185 Open a file (using SMBopenx)
186 WARNING: if you open with O_WRONLY then getattrE won't work!
187 ****************************************************************************/
188 int smbcli_open(struct smbcli_tree *tree, const char *fname, int flags,
189 int share_mode);
191 /****************************************************************************
192 Close a file.
193 ****************************************************************************/
194 NTSTATUS smbcli_close(struct smbcli_tree *tree, int fnum);
196 /****************************************************************************
197 send a lock with a specified locktype
198 this is used for testing LOCKING_ANDX_CANCEL_LOCK
199 ****************************************************************************/
200 NTSTATUS smbcli_locktype(struct smbcli_tree *tree, int fnum,
201 uint32_t offset, uint32_t len, int timeout,
202 uint8_t locktype);
204 /****************************************************************************
205 Lock a file.
206 ****************************************************************************/
207 NTSTATUS smbcli_lock(struct smbcli_tree *tree, int fnum,
208 uint32_t offset, uint32_t len, int timeout,
209 enum brl_type lock_type);
211 /****************************************************************************
212 Unlock a file.
213 ****************************************************************************/
214 NTSTATUS smbcli_unlock(struct smbcli_tree *tree, int fnum, uint32_t offset, uint32_t len);
216 /****************************************************************************
217 Lock a file with 64 bit offsets.
218 ****************************************************************************/
219 NTSTATUS smbcli_lock64(struct smbcli_tree *tree, int fnum,
220 off_t offset, off_t len, int timeout,
221 enum brl_type lock_type);
223 /****************************************************************************
224 Unlock a file with 64 bit offsets.
225 ****************************************************************************/
226 NTSTATUS smbcli_unlock64(struct smbcli_tree *tree, int fnum, off_t offset,
227 off_t len);
229 /****************************************************************************
230 Do a SMBgetattrE call.
231 ****************************************************************************/
232 NTSTATUS smbcli_getattrE(struct smbcli_tree *tree, int fnum,
233 uint16_t *attr, size_t *size,
234 time_t *c_time, time_t *a_time, time_t *m_time);
236 /****************************************************************************
237 Do a SMBgetatr call
238 ****************************************************************************/
239 NTSTATUS smbcli_getatr(struct smbcli_tree *tree, const char *fname,
240 uint16_t *attr, size_t *size, time_t *t);
242 /****************************************************************************
243 Do a SMBsetatr call.
244 ****************************************************************************/
245 NTSTATUS smbcli_setatr(struct smbcli_tree *tree, const char *fname, uint16_t mode,
246 time_t t);
248 /****************************************************************************
249 Do a setfileinfo basic_info call.
250 ****************************************************************************/
251 NTSTATUS smbcli_fsetatr(struct smbcli_tree *tree, int fnum, uint16_t mode,
252 NTTIME create_time, NTTIME access_time,
253 NTTIME write_time, NTTIME change_time);
255 /****************************************************************************
256 truncate a file to a given size
257 ****************************************************************************/
258 NTSTATUS smbcli_ftruncate(struct smbcli_tree *tree, int fnum, uint64_t size);
260 /****************************************************************************
261 Check for existence of a dir.
262 ****************************************************************************/
263 NTSTATUS smbcli_chkpath(struct smbcli_tree *tree, const char *path);
265 /****************************************************************************
266 Query disk space.
267 ****************************************************************************/
268 NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, uint32_t *bsize,
269 uint64_t *total, uint64_t *avail);
271 /****************************************************************************
272 Create and open a temporary file.
273 ****************************************************************************/
274 int smbcli_ctemp(struct smbcli_tree *tree, const char *path, char **tmp_path);
276 /****************************************************************************
277 Interpret a long filename structure.
278 ****************************************************************************/
279 int smbcli_list_new(struct smbcli_tree *tree, const char *Mask, uint16_t attribute,
280 enum smb_search_data_level level,
281 void (*fn)(struct clilist_file_info *, const char *, void *),
282 void *caller_state);
284 /****************************************************************************
285 Interpret a short filename structure.
286 The length of the structure is returned.
287 ****************************************************************************/
288 int smbcli_list_old(struct smbcli_tree *tree, const char *Mask, uint16_t attribute,
289 void (*fn)(struct clilist_file_info *, const char *, void *),
290 void *caller_state);
292 /****************************************************************************
293 Do a directory listing, calling fn on each file found.
294 This auto-switches between old and new style.
295 ****************************************************************************/
296 int smbcli_list(struct smbcli_tree *tree, const char *Mask,uint16_t attribute,
297 void (*fn)(struct clilist_file_info *, const char *, void *), void *state);
299 /****************************************************************************
300 send a qpathinfo call
301 ****************************************************************************/
302 NTSTATUS smbcli_qpathinfo(struct smbcli_tree *tree, const char *fname,
303 time_t *c_time, time_t *a_time, time_t *m_time,
304 size_t *size, uint16_t *mode);
306 /****************************************************************************
307 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
308 ****************************************************************************/
309 NTSTATUS smbcli_qpathinfo2(struct smbcli_tree *tree, const char *fname,
310 time_t *c_time, time_t *a_time, time_t *m_time,
311 time_t *w_time, size_t *size, uint16_t *mode,
312 ino_t *ino);
314 /****************************************************************************
315 send a qfileinfo QUERY_FILE_NAME_INFO call
316 ****************************************************************************/
317 NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name);
319 /****************************************************************************
320 send a qfileinfo call
321 ****************************************************************************/
322 NTSTATUS smbcli_qfileinfo(struct smbcli_tree *tree, int fnum,
323 uint16_t *mode, size_t *size,
324 time_t *c_time, time_t *a_time, time_t *m_time,
325 time_t *w_time, ino_t *ino);
327 /****************************************************************************
328 send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
329 ****************************************************************************/
330 NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname,
331 const char **alt_name);
333 /* The following definitions come from ../source4/libcli/climessage.c */
336 /****************************************************************************
337 start a message sequence
338 ****************************************************************************/
339 bool smbcli_message_start(struct smbcli_tree *tree, const char *host, const char *username,
340 int *grp);
342 /****************************************************************************
343 send a message
344 ****************************************************************************/
345 bool smbcli_message_text(struct smbcli_tree *tree, char *msg, int len, int grp);
347 /****************************************************************************
348 end a message
349 ****************************************************************************/
350 bool smbcli_message_end(struct smbcli_tree *tree, int grp);
352 int smbcli_deltree(struct smbcli_tree *tree, const char *dname);
354 #endif /* __LIBCLI_H__ */