2 Unix SMB/Netbios implementation.
3 SMB client library implementation
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000, 2002
6 Copyright (C) John Terpstra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
8 Copyright (C) Derrell Lipman 2003-2008
9 Copyright (C) Jeremy Allison 2007, 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #ifndef _LIBSMB_INTERNAL_H_
29 #define _LIBSMB_INTERNAL_H_
31 #include "../include/libsmbclient.h"
32 #include "libsmb/clirap.h"
34 #define SMBC_MAX_NAME 1023
37 * DOS Attribute values (used internally)
39 struct DOS_ATTR_DESC
{
50 * Extension of libsmbclient.h's #defines
52 #define SMB_CTX_FLAG_USE_NT_HASH (1 << 4)
55 * Internal flags for extended attributes
58 /* internal mode values */
59 #define SMBC_XATTR_MODE_ADD 1
60 #define SMBC_XATTR_MODE_REMOVE 2
61 #define SMBC_XATTR_MODE_REMOVE_ALL 3
62 #define SMBC_XATTR_MODE_SET 4
63 #define SMBC_XATTR_MODE_CHOWN 5
64 #define SMBC_XATTR_MODE_CHGRP 6
66 /*We should test for this in configure ... */
68 #define ENOTSUP EOPNOTSUPP
73 struct cli_state
*cli
;
79 struct policy_handle pol
;
80 time_t last_echo_time
;
82 struct _SMBCSRV
*next
, *prev
;
86 * Keep directory entries in a list
88 struct smbc_dir_list
{
89 struct smbc_dir_list
*next
;
90 struct smbc_dirent
*dirent
;
93 struct smbc_dirplus_list
{
94 struct smbc_dirplus_list
*next
;
95 struct libsmb_file_info
*smb_finfo
;
100 * Structure for open file management
105 * cache of cli_state we opened cli_fd on.
106 * Due to DFS can be a subsidiary connection to srv->cli
108 struct cli_state
*targetcli
;
111 struct _SMBCSRV
*srv
;
113 struct smbc_dir_list
*dir_list
, *dir_end
, *dir_next
;
114 struct smbc_dirplus_list
*dirplus_list
, *dirplus_end
, *dirplus_next
;
115 int dir_type
, dir_error
;
117 struct _SMBCFILE
*next
, *prev
;
124 struct SMBC_internal_data
{
126 /* True when this handle is initialized */
129 /* dirent pointer location */
130 struct smbc_dirent dirent
;
132 * Leave room for any urlencoded filename and the comment field.
134 * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
135 * plus a couple of null terminators (one after the filename,
136 * one after the comment).
138 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
141 char _dirent_name
[1024];
144 * server connection list
154 * Support "Create Time" in get/set with the *xattr() functions, if
155 * true. This replaces the dos attribute strings C_TIME, A_TIME and
156 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
157 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
158 * names and to not support CREATE time, for backward compatibility.
160 bool full_time_names
;
163 * Enable POSIX extensions before opening files/directories
164 * Will silently ignore if the server does not support the POSIX
168 bool posix_extensions
;
171 * The share mode of a file being opened. To match POSIX semantics
172 * (and maintain backward compatibility), DENY_NONE is the default.
174 smbc_share_mode share_mode
;
177 * Authentication function which includes the context. This will be
178 * used if set; otherwise context->callbacks.auth_fn() will be used.
180 smbc_get_auth_data_with_context_fn auth_fn_with_context
;
183 * An opaque (to this library) user data handle which can be set
184 * and retrieved with smbc_option_set() and smbc_option_get().
189 * Should we attempt UNIX smb encryption ?
190 * Set to 0 if we should never attempt, set to 1 if
191 * encryption requested, set to 2 if encryption required.
193 smbc_smb_encrypt_level smb_encryption_level
;
196 * Should we request case sensitivity of file names?
201 * Credentials needed for DFS traversal.
203 struct cli_credentials
*creds
;
205 struct smbc_server_cache
* server_cache
;
207 /* POSIX emulation functions */
210 #if 0 /* Left in libsmbclient.h for backward compatibility */
211 smbc_open_fn open_fn
;
212 smbc_creat_fn creat_fn
;
213 smbc_read_fn read_fn
;
214 smbc_write_fn write_fn
;
215 smbc_unlink_fn unlink_fn
;
216 smbc_rename_fn rename_fn
;
217 smbc_lseek_fn lseek_fn
;
218 smbc_stat_fn stat_fn
;
219 smbc_fstat_fn fstat_fn
;
221 smbc_statvfs_fn statvfs_fn
;
222 smbc_fstatvfs_fn fstatvfs_fn
;
223 smbc_ftruncate_fn ftruncate_fn
;
224 #if 0 /* Left in libsmbclient.h for backward compatibility */
225 smbc_close_fn close_fn
;
226 smbc_opendir_fn opendir_fn
;
227 smbc_closedir_fn closedir_fn
;
228 smbc_readdir_fn readdir_fn
;
229 smbc_getdents_fn getdents_fn
;
230 smbc_mkdir_fn mkdir_fn
;
231 smbc_rmdir_fn rmdir_fn
;
232 smbc_telldir_fn telldir_fn
;
233 smbc_lseekdir_fn lseekdir_fn
;
234 smbc_fstatdir_fn fstatdir_fn
;
235 smbc_chmod_fn chmod_fn
;
236 smbc_utimes_fn utimes_fn
;
237 smbc_setxattr_fn setxattr_fn
;
238 smbc_getxattr_fn getxattr_fn
;
239 smbc_removexattr_fn removexattr_fn
;
240 smbc_listxattr_fn listxattr_fn
;
244 #if 0 /* Left in libsmbclient.h for backward compatibility */
245 /* Printing-related functions */
248 smbc_print_file_fn print_file_fn
;
249 smbc_open_print_job_fn open_print_job_fn
;
250 smbc_list_print_jobs_fn list_print_jobs_fn
;
251 smbc_unlink_print_job_fn unlink_print_job_fn
;
255 /* SMB high-level functions */
258 smbc_splice_fn splice_fn
;
259 smbc_notify_fn notify_fn
;
264 struct loadparm_context
*lp_ctx
;
267 /* Functions in libsmb_cache.c */
269 SMBC_add_cached_server(SMBCCTX
* context
,
273 const char * workgroup
,
274 const char * username
);
277 SMBC_get_cached_server(SMBCCTX
* context
,
280 const char * workgroup
,
284 SMBC_remove_cached_server(SMBCCTX
* context
,
288 SMBC_purge_cached_servers(SMBCCTX
* context
);
291 /* Functions in libsmb_dir.c */
293 SMBC_check_options(char *server
,
299 SMBC_opendir_ctx(SMBCCTX
*context
,
303 SMBC_closedir_ctx(SMBCCTX
*context
,
307 SMBC_readdir_ctx(SMBCCTX
*context
,
310 const struct libsmb_file_info
*
311 SMBC_readdirplus_ctx(SMBCCTX
*context
,
314 const struct libsmb_file_info
*
315 SMBC_readdirplus2_ctx(SMBCCTX
*context
,
320 SMBC_getdents_ctx(SMBCCTX
*context
,
322 struct smbc_dirent
*dirp
,
326 SMBC_mkdir_ctx(SMBCCTX
*context
,
331 SMBC_rmdir_ctx(SMBCCTX
*context
,
335 SMBC_telldir_ctx(SMBCCTX
*context
,
339 SMBC_lseekdir_ctx(SMBCCTX
*context
,
344 SMBC_fstatdir_ctx(SMBCCTX
*context
,
349 SMBC_chmod_ctx(SMBCCTX
*context
,
354 SMBC_utimes_ctx(SMBCCTX
*context
,
356 struct timeval
*tbuf
);
359 SMBC_unlink_ctx(SMBCCTX
*context
,
363 SMBC_rename_ctx(SMBCCTX
*ocontext
,
369 SMBC_notify_ctx(SMBCCTX
*c
, SMBCFILE
*dir
, smbc_bool recursive
,
370 uint32_t completion_filter
, unsigned callback_timeout_ms
,
371 smbc_notify_callback_fn cb
, void *private_data
);
375 /* Functions in libsmb_file.c */
377 SMBC_open_ctx(SMBCCTX
*context
,
383 SMBC_creat_ctx(SMBCCTX
*context
,
388 SMBC_read_ctx(SMBCCTX
*context
,
394 SMBC_write_ctx(SMBCCTX
*context
,
400 SMBC_splice_ctx(SMBCCTX
*context
,
404 int (*splice_cb
)(off_t n
, void *priv
),
408 SMBC_close_ctx(SMBCCTX
*context
,
412 SMBC_getatr(SMBCCTX
* context
,
418 SMBC_setatr(SMBCCTX
* context
, SMBCSRV
*srv
, char *path
,
419 struct timespec create_time
,
420 struct timespec access_time
,
421 struct timespec write_time
,
422 struct timespec change_time
,
426 SMBC_lseek_ctx(SMBCCTX
*context
,
432 SMBC_ftruncate_ctx(SMBCCTX
*context
,
437 /* Functions in libsmb_misc.c */
438 bool SMBC_dlist_contains(SMBCFILE
* list
, SMBCFILE
*p
);
440 /* Functions in libsmb_path.c */
442 SMBC_parse_path(TALLOC_CTX
*ctx
,
455 /* Functions in libsmb_printjob.c */
457 SMBC_open_print_job_ctx(SMBCCTX
*context
,
461 SMBC_print_file_ctx(SMBCCTX
*c_file
,
467 SMBC_list_print_jobs_ctx(SMBCCTX
*context
,
469 smbc_list_print_job_fn fn
);
472 SMBC_unlink_print_job_ctx(SMBCCTX
*context
,
477 /* Functions in libsmb_server.c */
479 SMBC_check_server(SMBCCTX
* context
,
483 SMBC_remove_unused_server(SMBCCTX
* context
,
487 SMBC_get_auth_data(const char *server
, const char *share
,
488 char *workgroup_buf
, int workgroup_buf_len
,
489 char *username_buf
, int username_buf_len
,
490 char *password_buf
, int password_buf_len
);
493 SMBC_find_server(TALLOC_CTX
*ctx
,
502 SMBC_server(TALLOC_CTX
*ctx
,
504 bool connect_if_not_found
,
513 SMBC_attr_server(TALLOC_CTX
*ctx
,
523 /* Functions in libsmb_stat.c */
524 void setup_stat(struct stat
*st
,
530 struct timespec access_time_ts
,
531 struct timespec change_time_ts
,
532 struct timespec write_time_ts
);
533 void setup_stat_from_stat_ex(const struct stat_ex
*stex
,
538 SMBC_stat_ctx(SMBCCTX
*context
,
543 SMBC_fstat_ctx(SMBCCTX
*context
,
549 SMBC_statvfs_ctx(SMBCCTX
*context
,
555 SMBC_fstatvfs_ctx(SMBCCTX
*context
,
560 /* Functions in libsmb_xattr.c */
562 SMBC_setxattr_ctx(SMBCCTX
*context
,
570 SMBC_getxattr_ctx(SMBCCTX
*context
,
577 SMBC_removexattr_ctx(SMBCCTX
*context
,
582 SMBC_listxattr_ctx(SMBCCTX
*context
,