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"
33 #define SMBC_MAX_NAME 1023
34 #define SMBC_FILE_MODE (S_IFREG | 0444)
35 #define SMBC_DIR_MODE (S_IFDIR | 0555)
38 * DOS Attribute values (used internally)
40 typedef struct DOS_ATTR_DESC {
52 * Internal flags for extended attributes
55 /* internal mode values */
56 #define SMBC_XATTR_MODE_ADD 1
57 #define SMBC_XATTR_MODE_REMOVE 2
58 #define SMBC_XATTR_MODE_REMOVE_ALL 3
59 #define SMBC_XATTR_MODE_SET 4
60 #define SMBC_XATTR_MODE_CHOWN 5
61 #define SMBC_XATTR_MODE_CHGRP 6
63 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
65 /*We should test for this in configure ... */
67 #define ENOTSUP EOPNOTSUPP
72 struct cli_state *cli;
84 * Keep directory entries in a list
86 struct smbc_dir_list {
87 struct smbc_dir_list *next;
88 struct smbc_dirent *dirent;
93 * Structure for open file management
101 struct smbc_dir_list *dir_list, *dir_end, *dir_next;
102 int dir_type, dir_error;
104 SMBCFILE *next, *prev;
111 struct SMBC_internal_data {
113 /* True when this handle is initialized */
116 #if 0 /* Left in libsmbclient.h for backward compatibility */
117 /* Netbios name used for making connections */
120 /* Workgroup used for making connections */
123 /* Username used for making connections */
129 /* Connection timeout value */
133 /* dirent pointer location
135 * Leave room for any urlencoded filename and the comment field.
137 * We really should use sizeof(struct smbc_dirent) plus (NAME_MAX * 3)
138 * plus whatever the max length of a comment is, plus a couple of null
139 * terminators (one after the filename, one after the comment).
141 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
147 * server connection list
157 * Log to standard error instead of the more typical standard output
162 * Support "Create Time" in get/set with the *xattr() functions, if
163 * true. This replaces the dos attribute strings C_TIME, A_TIME and
164 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
165 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
166 * names and to not support CREATE time, for backward compatibility.
168 bool full_time_names;
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;
195 #if 0 /* Left in libsmbclient.h for backward compatibility */
197 * From how many local master browsers should the list of
198 * workgroups be retrieved? It can take up to 12 minutes or
199 * longer after a server becomes a local master browser, for
200 * it to have the entire browse list (the list of
201 * workgroups/domains) from an entire network. Since a client
202 * never knows which local master browser will be found first,
203 * the one which is found first and used to retrieve a browse
204 * list may have an incomplete or empty browse list. By
205 * requesting the browse list from multiple local master
206 * browsers, a more complete list can be generated. For small
207 * networks (few workgroups), it is recommended that this
208 * value be set to 0, causing the browse lists from all found
209 * local master browsers to be retrieved and merged. For
210 * networks with many workgroups, a suitable value for this
211 * variable is probably somewhere around 3. (Default: 3).
213 int browse_max_lmb_count;
216 * There is a difference in the desired return strings from
217 * smbc_readdir() depending upon whether the filenames are to
218 * be displayed to the user, or whether they are to be
219 * appended to the path name passed to smbc_opendir() to call
220 * a further smbc_ function (e.g. open the file with
221 * smbc_open()). In the former case, the filename should be
222 * in "human readable" form. In the latter case, the smbc_
223 * functions expect a URL which must be url-encoded. Those
224 * functions decode the URL. If, for example, smbc_readdir()
225 * returned a file name of "abc%20def.txt", passing a path
226 * with this file name attached to smbc_open() would cause
227 * smbc_open to attempt to open the file "abc def.txt" since
228 * the %20 is decoded into a space.
230 * Set this option to True if the names returned by
231 * smbc_readdir() should be url-encoded such that they can be
232 * passed back to another smbc_ call. Set it to False if the
233 * names returned by smbc_readdir() are to be presented to the
236 * For backwards compatibility, this option defaults to False.
238 bool urlencode_readdir_entries;
241 * Some Windows versions appear to have a limit to the number
242 * of concurrent SESSIONs and/or TREE CONNECTions. In
243 * one-shot programs (i.e. the program runs and then quickly
244 * ends, thereby shutting down all connections), it is
245 * probably reasonable to establish a new connection for each
246 * share. In long-running applications, the limitation can be
247 * avoided by using only a single connection to each server,
248 * and issuing a new TREE CONNECT when the share is accessed.
250 bool one_share_per_server;
252 /* Kerberos-related flags */
254 bool fallback_after_kerberos;
256 /* Don't try to do automatic anonymous login */
257 bool no_auto_anonymous_login;
259 /* Server-related functions */
262 smbc_get_auth_data_fn get_auth_data_fn;
263 smbc_check_server_fn check_server_fn;
264 smbc_remove_unused_server_fn remove_unused_server_fn;
267 /* Cache-related functions */
270 struct smbc_server_cache * server_cache_data;
271 smbc_add_cached_srv_fn add_cached_server_fn;
272 smbc_get_cached_srv_fn get_cached_server_fn;
273 smbc_remove_cached_srv_fn remove_cached_server_fn;
274 smbc_purge_cached_srv_fn purge_cached_server_fn;
278 /* POSIX emulation functions */
281 #if 0 /* Left in libsmbclient.h for backward compatibility */
282 smbc_open_fn open_fn;
283 smbc_creat_fn creat_fn;
284 smbc_read_fn read_fn;
285 smbc_write_fn write_fn;
286 smbc_unlink_fn unlink_fn;
287 smbc_rename_fn rename_fn;
288 smbc_lseek_fn lseek_fn;
289 smbc_stat_fn stat_fn;
290 smbc_fstat_fn fstat_fn;
292 smbc_ftruncate_fn ftruncate_fn;
293 #if 0 /* Left in libsmbclient.h for backward compatibility */
294 smbc_close_fn close_fn;
295 smbc_opendir_fn opendir_fn;
296 smbc_closedir_fn closedir_fn;
297 smbc_readdir_fn readdir_fn;
298 smbc_getdents_fn getdents_fn;
299 smbc_mkdir_fn mkdir_fn;
300 smbc_rmdir_fn rmdir_fn;
301 smbc_telldir_fn telldir_fn;
302 smbc_lseekdir_fn lseekdir_fn;
303 smbc_fstatdir_fn fstatdir_fn;
304 smbc_chmod_fn chmod_fn;
305 smbc_utimes_fn utimes_fn;
306 smbc_setxattr_fn setxattr_fn;
307 smbc_getxattr_fn getxattr_fn;
308 smbc_removexattr_fn removexattr_fn;
309 smbc_listxattr_fn listxattr_fn;
313 #if 0 /* Left in libsmbclient.h for backward compatibility */
314 /* Printing-related functions */
317 smbc_print_file_fn print_file_fn;
318 smbc_open_print_job_fn open_print_job_fn;
319 smbc_list_print_jobs_fn list_print_jobs_fn;
320 smbc_unlink_print_job_fn unlink_print_job_fn;
324 #if 0 /* None available yet */
325 /* SMB high-level functions */
333 /* Functions in libsmb_cache.c */
335 SMBC_add_cached_server(SMBCCTX * context,
339 const char * workgroup,
340 const char * username);
343 SMBC_get_cached_server(SMBCCTX * context,
346 const char * workgroup,
350 SMBC_remove_cached_server(SMBCCTX * context,
354 SMBC_purge_cached_servers(SMBCCTX * context);
357 /* Functions in libsmb_dir.c */
359 SMBC_check_options(char *server,
365 SMBC_opendir_ctx(SMBCCTX *context,
369 SMBC_closedir_ctx(SMBCCTX *context,
373 SMBC_readdir_ctx(SMBCCTX *context,
377 SMBC_getdents_ctx(SMBCCTX *context,
379 struct smbc_dirent *dirp,
383 SMBC_mkdir_ctx(SMBCCTX *context,
388 SMBC_rmdir_ctx(SMBCCTX *context,
392 SMBC_telldir_ctx(SMBCCTX *context,
396 SMBC_lseekdir_ctx(SMBCCTX *context,
401 SMBC_fstatdir_ctx(SMBCCTX *context,
406 SMBC_chmod_ctx(SMBCCTX *context,
411 SMBC_utimes_ctx(SMBCCTX *context,
413 struct timeval *tbuf);
416 SMBC_unlink_ctx(SMBCCTX *context,
420 SMBC_rename_ctx(SMBCCTX *ocontext,
426 /* Functions in libsmb_file.c */
428 SMBC_open_ctx(SMBCCTX *context,
434 SMBC_creat_ctx(SMBCCTX *context,
439 SMBC_read_ctx(SMBCCTX *context,
445 SMBC_write_ctx(SMBCCTX *context,
451 SMBC_close_ctx(SMBCCTX *context,
455 SMBC_getatr(SMBCCTX * context,
460 struct timespec *create_time_ts,
461 struct timespec *access_time_ts,
462 struct timespec *write_time_ts,
463 struct timespec *change_time_ts,
467 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
475 SMBC_lseek_ctx(SMBCCTX *context,
481 SMBC_ftruncate_ctx(SMBCCTX *context,
486 /* Functions in libsmb_misc.c */
488 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
491 SMBC_errno(SMBCCTX *context,
492 struct cli_state *c);
495 /* Functions in libsmb_path.c */
497 SMBC_urldecode(char *dest,
499 size_t max_dest_len);
502 SMBC_urlencode(char *dest,
507 SMBC_parse_path(TALLOC_CTX *ctx,
519 /* Functions in libsmb_printjob.c */
521 SMBC_open_print_job_ctx(SMBCCTX *context,
525 SMBC_print_file_ctx(SMBCCTX *c_file,
531 SMBC_list_print_jobs_ctx(SMBCCTX *context,
533 smbc_list_print_job_fn fn);
536 SMBC_unlink_print_job_ctx(SMBCCTX *context,
541 /* Functions in libsmb_server.c */
543 SMBC_check_server(SMBCCTX * context,
547 SMBC_remove_unused_server(SMBCCTX * context,
551 SMBC_call_auth_fn(TALLOC_CTX *ctx,
560 SMBC_get_auth_data(const char *server, const char *share,
561 char *workgroup_buf, int workgroup_buf_len,
562 char *username_buf, int username_buf_len,
563 char *password_buf, int password_buf_len);
566 SMBC_find_server(TALLOC_CTX *ctx,
575 SMBC_server(TALLOC_CTX *ctx,
577 bool connect_if_not_found,
585 SMBC_attr_server(TALLOC_CTX *ctx,
594 /* Functions in libsmb_stat.c */
596 SMBC_stat_ctx(SMBCCTX *context,
601 SMBC_fstat_ctx(SMBCCTX *context,
606 /* Functions in libsmb_xattr.c */
608 SMBC_setxattr_ctx(SMBCCTX *context,
616 SMBC_getxattr_ctx(SMBCCTX *context,
623 SMBC_removexattr_ctx(SMBCCTX *context,
628 SMBC_listxattr_ctx(SMBCCTX *context,