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/>.
24 #include "librpc/gen_ndr/nbt.h"
25 #include "libcli/raw/libcliraw.h"
27 struct substitute_context
;
30 smbcli_state: internal state used in libcli library for single-threaded callers,
31 i.e. a single session on a single socket.
34 struct smbcli_options options
;
35 struct smbcli_socket
*sock
; /* NULL if connected */
36 struct smbcli_transport
*transport
;
37 struct smbcli_session
*session
;
38 struct smbcli_tree
*tree
;
39 struct substitute_context
*substitute
;
40 struct smblsa_state
*lsa
;
43 struct clilist_file_info
{
48 const char *short_name
;
56 struct cli_credentials
;
57 struct tevent_context
;
59 /* passed to br lock code. */
67 #include "libcli/raw/libcliraw.h"
68 struct gensec_settings
;
70 ssize_t
smbcli_read(struct smbcli_tree
*tree
, int fnum
, void *_buf
, off_t offset
, size_t size
);
72 /****************************************************************************
74 write_mode: 0x0001 disallow write caching
75 0x0002 return bytes remaining
76 0x0004 use raw named pipe protocol
77 0x0008 start of message mode named pipe protocol
78 ****************************************************************************/
79 ssize_t
smbcli_write(struct smbcli_tree
*tree
,
80 int fnum
, uint16_t write_mode
,
81 const void *_buf
, off_t offset
, size_t size
);
83 /****************************************************************************
84 write to a file using a SMBwrite and not bypassing 0 byte writes
85 ****************************************************************************/
86 ssize_t
smbcli_smbwrite(struct smbcli_tree
*tree
,
87 int fnum
, const void *_buf
, off_t offset
, size_t size1
);
89 bool smbcli_socket_connect(struct smbcli_state
*cli
, const char *server
,
91 struct tevent_context
*ev_ctx
,
92 struct resolve_context
*resolve_ctx
,
93 struct smbcli_options
*options
,
94 const char *socket_options
,
95 struct nbt_name
*calling
,
96 struct nbt_name
*called
);
97 NTSTATUS
smbcli_negprot(struct smbcli_state
*cli
, bool unicode
, int maxprotocol
);
98 NTSTATUS
smbcli_session_setup(struct smbcli_state
*cli
,
99 struct cli_credentials
*credentials
,
100 const char *workgroup
,
101 struct smbcli_session_options options
,
102 struct gensec_settings
*gensec_settings
);
103 NTSTATUS
smbcli_tconX(struct smbcli_state
*cli
, const char *sharename
,
104 const char *devtype
, const char *password
);
105 NTSTATUS
smbcli_full_connection(TALLOC_CTX
*parent_ctx
,
106 struct smbcli_state
**ret_cli
,
109 const char *sharename
,
111 const char *socket_options
,
112 struct cli_credentials
*credentials
,
113 struct resolve_context
*resolve_ctx
,
114 struct tevent_context
*ev
,
115 struct smbcli_options
*options
,
116 struct smbcli_session_options
*session_options
,
117 struct gensec_settings
*gensec_settings
);
118 NTSTATUS
smbcli_tdis(struct smbcli_state
*cli
);
120 /****************************************************************************
121 Initialise a client state structure.
122 ****************************************************************************/
123 struct smbcli_state
*smbcli_state_init(TALLOC_CTX
*mem_ctx
);
124 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
125 char **hostname
, char **sharename
);
127 /****************************************************************************
128 Symlink a file (UNIX extensions).
129 ****************************************************************************/
130 NTSTATUS
smbcli_unix_symlink(struct smbcli_tree
*tree
, const char *fname_src
,
131 const char *fname_dst
);
133 /****************************************************************************
134 Hard a file (UNIX extensions).
135 ****************************************************************************/
136 NTSTATUS
smbcli_unix_hardlink(struct smbcli_tree
*tree
, const char *fname_src
,
137 const char *fname_dst
);
139 /****************************************************************************
140 chmod a file (UNIX extensions).
141 ****************************************************************************/
142 NTSTATUS
smbcli_unix_chmod(struct smbcli_tree
*tree
, const char *fname
, mode_t mode
);
144 /****************************************************************************
145 chown a file (UNIX extensions).
146 ****************************************************************************/
147 NTSTATUS
smbcli_unix_chown(struct smbcli_tree
*tree
, const char *fname
, uid_t uid
,
150 /****************************************************************************
152 ****************************************************************************/
153 NTSTATUS
smbcli_rename(struct smbcli_tree
*tree
, const char *fname_src
,
154 const char *fname_dst
);
156 /****************************************************************************
158 ****************************************************************************/
159 NTSTATUS
smbcli_unlink(struct smbcli_tree
*tree
, const char *fname
);
161 /****************************************************************************
162 Delete a wildcard pattern of files.
163 ****************************************************************************/
164 NTSTATUS
smbcli_unlink_wcard(struct smbcli_tree
*tree
, const char *fname
);
166 /****************************************************************************
168 ****************************************************************************/
169 NTSTATUS
smbcli_mkdir(struct smbcli_tree
*tree
, const char *dname
);
171 /****************************************************************************
173 ****************************************************************************/
174 NTSTATUS
smbcli_rmdir(struct smbcli_tree
*tree
, const char *dname
);
176 /****************************************************************************
177 Set or clear the delete on close flag.
178 ****************************************************************************/
179 NTSTATUS
smbcli_nt_delete_on_close(struct smbcli_tree
*tree
, int fnum
,
182 /****************************************************************************
183 Create/open a file - exposing the full horror of the NT API :-).
184 Used in CIFS-on-CIFS NTVFS.
185 ****************************************************************************/
186 int smbcli_nt_create_full(struct smbcli_tree
*tree
, const char *fname
,
187 uint32_t CreatFlags
, uint32_t DesiredAccess
,
188 uint32_t FileAttributes
, uint32_t ShareAccess
,
189 uint32_t CreateDisposition
, uint32_t CreateOptions
,
190 uint8_t SecurityFlags
);
192 /****************************************************************************
193 Open a file (using SMBopenx)
194 WARNING: if you open with O_WRONLY then getattrE won't work!
195 ****************************************************************************/
196 int smbcli_open(struct smbcli_tree
*tree
, const char *fname
, int flags
,
199 /****************************************************************************
201 ****************************************************************************/
202 NTSTATUS
smbcli_close(struct smbcli_tree
*tree
, int fnum
);
204 /****************************************************************************
205 send a lock with a specified locktype
206 this is used for testing LOCKING_ANDX_CANCEL_LOCK
207 ****************************************************************************/
208 NTSTATUS
smbcli_locktype(struct smbcli_tree
*tree
, int fnum
,
209 uint32_t offset
, uint32_t len
, int timeout
,
212 /****************************************************************************
214 ****************************************************************************/
215 NTSTATUS
smbcli_lock(struct smbcli_tree
*tree
, int fnum
,
216 uint32_t offset
, uint32_t len
, int timeout
,
217 enum brl_type lock_type
);
219 /****************************************************************************
221 ****************************************************************************/
222 NTSTATUS
smbcli_unlock(struct smbcli_tree
*tree
, int fnum
, uint32_t offset
, uint32_t len
);
224 /****************************************************************************
225 Lock a file with 64 bit offsets.
226 ****************************************************************************/
227 NTSTATUS
smbcli_lock64(struct smbcli_tree
*tree
, int fnum
,
228 off_t offset
, off_t len
, int timeout
,
229 enum brl_type lock_type
);
231 /****************************************************************************
232 Unlock a file with 64 bit offsets.
233 ****************************************************************************/
234 NTSTATUS
smbcli_unlock64(struct smbcli_tree
*tree
, int fnum
, off_t offset
,
237 /****************************************************************************
238 Do a SMBgetattrE call.
239 ****************************************************************************/
240 NTSTATUS
smbcli_getattrE(struct smbcli_tree
*tree
, int fnum
,
241 uint16_t *attr
, size_t *size
,
242 time_t *c_time
, time_t *a_time
, time_t *m_time
);
244 /****************************************************************************
246 ****************************************************************************/
247 NTSTATUS
smbcli_getatr(struct smbcli_tree
*tree
, const char *fname
,
248 uint16_t *attr
, size_t *size
, time_t *t
);
250 /****************************************************************************
252 ****************************************************************************/
253 NTSTATUS
smbcli_setatr(struct smbcli_tree
*tree
, const char *fname
, uint16_t mode
,
256 /****************************************************************************
257 Do a setfileinfo basic_info call.
258 ****************************************************************************/
259 NTSTATUS
smbcli_fsetatr(struct smbcli_tree
*tree
, int fnum
, uint16_t mode
,
260 NTTIME create_time
, NTTIME access_time
,
261 NTTIME write_time
, NTTIME change_time
);
263 /****************************************************************************
264 truncate a file to a given size
265 ****************************************************************************/
266 NTSTATUS
smbcli_ftruncate(struct smbcli_tree
*tree
, int fnum
, uint64_t size
);
268 /****************************************************************************
269 Check for existence of a dir.
270 ****************************************************************************/
271 NTSTATUS
smbcli_chkpath(struct smbcli_tree
*tree
, const char *path
);
273 /****************************************************************************
275 ****************************************************************************/
276 NTSTATUS
smbcli_dskattr(struct smbcli_tree
*tree
, uint32_t *bsize
,
277 uint64_t *total
, uint64_t *avail
);
279 /****************************************************************************
280 Create and open a temporary file.
281 ****************************************************************************/
282 int smbcli_ctemp(struct smbcli_tree
*tree
, const char *path
, char **tmp_path
);
284 /****************************************************************************
285 Interpret a long filename structure.
286 ****************************************************************************/
287 int smbcli_list_new(struct smbcli_tree
*tree
, const char *Mask
, uint16_t attribute
,
288 enum smb_search_data_level level
,
289 void (*fn
)(struct clilist_file_info
*, const char *, void *),
292 /****************************************************************************
293 Interpret a short filename structure.
294 The length of the structure is returned.
295 ****************************************************************************/
296 int smbcli_list_old(struct smbcli_tree
*tree
, const char *Mask
, uint16_t attribute
,
297 void (*fn
)(struct clilist_file_info
*, const char *, void *),
300 /****************************************************************************
301 Do a directory listing, calling fn on each file found.
302 This auto-switches between old and new style.
303 ****************************************************************************/
304 int smbcli_list(struct smbcli_tree
*tree
, const char *Mask
,uint16_t attribute
,
305 void (*fn
)(struct clilist_file_info
*, const char *, void *), void *state
);
307 /****************************************************************************
308 send a qpathinfo call
309 ****************************************************************************/
310 NTSTATUS
smbcli_qpathinfo(struct smbcli_tree
*tree
, const char *fname
,
311 time_t *c_time
, time_t *a_time
, time_t *m_time
,
312 size_t *size
, uint16_t *mode
);
314 /****************************************************************************
315 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
316 ****************************************************************************/
317 NTSTATUS
smbcli_qpathinfo2(struct smbcli_tree
*tree
, const char *fname
,
318 time_t *c_time
, time_t *a_time
, time_t *m_time
,
319 time_t *w_time
, size_t *size
, uint16_t *mode
,
322 /****************************************************************************
323 send a qfileinfo QUERY_FILE_NAME_INFO call
324 ****************************************************************************/
325 NTSTATUS
smbcli_qfilename(struct smbcli_tree
*tree
, int fnum
, const char **name
);
327 /****************************************************************************
328 send a qfileinfo call
329 ****************************************************************************/
330 NTSTATUS
smbcli_qfileinfo(struct smbcli_tree
*tree
, int fnum
,
331 uint16_t *mode
, size_t *size
,
332 time_t *c_time
, time_t *a_time
, time_t *m_time
,
333 time_t *w_time
, ino_t
*ino
);
335 /****************************************************************************
336 send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
337 ****************************************************************************/
338 NTSTATUS
smbcli_qpathinfo_alt_name(struct smbcli_tree
*tree
, const char *fname
,
339 const char **alt_name
);
341 /* The following definitions come from ../source4/libcli/climessage.c */
344 /****************************************************************************
345 start a message sequence
346 ****************************************************************************/
347 bool smbcli_message_start(struct smbcli_tree
*tree
, const char *host
, const char *username
,
350 /****************************************************************************
352 ****************************************************************************/
353 bool smbcli_message_text(struct smbcli_tree
*tree
, char *msg
, int len
, int grp
);
355 /****************************************************************************
357 ****************************************************************************/
358 bool smbcli_message_end(struct smbcli_tree
*tree
, int grp
);
360 int smbcli_deltree(struct smbcli_tree
*tree
, const char *dname
);
362 #endif /* __LIBCLI_H__ */