s4:lib/tls: add tstream_tls_params_client_lpcfg()
[samba.git] / source3 / include / libsmb_internal.h
blob113111532e0462cc70c2db51badba46561b5a285
1 /*
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/>.
25 #include "includes.h"
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 {
40 int mode;
41 off_t size;
42 time_t create_time;
43 time_t access_time;
44 time_t write_time;
45 time_t change_time;
46 SMB_INO_T inode;
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 ... */
67 #ifndef ENOTSUP
68 #define ENOTSUP EOPNOTSUPP
69 #endif
72 struct _SMBCSRV {
73 struct cli_state *cli;
74 dev_t dev;
75 bool no_pathinfo;
76 bool no_pathinfo2;
77 bool no_pathinfo3;
78 bool no_nt_session;
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;
96 uint64_t ino;
100 * Structure for open file management
102 struct _SMBCFILE {
103 int cli_fd;
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;
109 char *fname;
110 off_t offset;
111 struct _SMBCSRV *srv;
112 bool file;
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;
122 * Context structure
124 struct SMBC_internal_data {
126 /* True when this handle is initialized */
127 bool 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
139 * anyplace else?
141 char _dirent_name[1024];
144 * server connection list
146 SMBCSRV * servers;
149 * open file/dir list
151 SMBCFILE * files;
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
165 * extensions
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().
186 void * user_data;
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?
198 bool case_sensitive;
201 * Credentials needed for DFS traversal.
203 struct cli_credentials *creds;
205 struct smbc_server_cache * server_cache;
207 /* POSIX emulation functions */
208 struct
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;
220 #endif
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;
241 #endif
242 } posix_emu;
244 #if 0 /* Left in libsmbclient.h for backward compatibility */
245 /* Printing-related functions */
246 struct
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;
252 } printing;
253 #endif
255 /* SMB high-level functions */
256 struct
258 smbc_splice_fn splice_fn;
259 smbc_notify_fn notify_fn;
260 } smb;
262 uint16_t port;
264 struct loadparm_context *lp_ctx;
267 /* Functions in libsmb_cache.c */
269 SMBC_add_cached_server(SMBCCTX * context,
270 SMBCSRV * newsrv,
271 const char * server,
272 const char * share,
273 const char * workgroup,
274 const char * username);
276 SMBCSRV *
277 SMBC_get_cached_server(SMBCCTX * context,
278 const char * server,
279 const char * share,
280 const char * workgroup,
281 const char * user);
284 SMBC_remove_cached_server(SMBCCTX * context,
285 SMBCSRV * server);
288 SMBC_purge_cached_servers(SMBCCTX * context);
291 /* Functions in libsmb_dir.c */
293 SMBC_check_options(char *server,
294 char *share,
295 char *path,
296 char *options);
298 SMBCFILE *
299 SMBC_opendir_ctx(SMBCCTX *context,
300 const char *fname);
303 SMBC_closedir_ctx(SMBCCTX *context,
304 SMBCFILE *dir);
306 struct smbc_dirent *
307 SMBC_readdir_ctx(SMBCCTX *context,
308 SMBCFILE *dir);
310 const struct libsmb_file_info *
311 SMBC_readdirplus_ctx(SMBCCTX *context,
312 SMBCFILE *dir);
314 const struct libsmb_file_info *
315 SMBC_readdirplus2_ctx(SMBCCTX *context,
316 SMBCFILE *dir,
317 struct stat *st);
320 SMBC_getdents_ctx(SMBCCTX *context,
321 SMBCFILE *dir,
322 struct smbc_dirent *dirp,
323 int count);
326 SMBC_mkdir_ctx(SMBCCTX *context,
327 const char *fname,
328 mode_t mode);
331 SMBC_rmdir_ctx(SMBCCTX *context,
332 const char *fname);
334 off_t
335 SMBC_telldir_ctx(SMBCCTX *context,
336 SMBCFILE *dir);
339 SMBC_lseekdir_ctx(SMBCCTX *context,
340 SMBCFILE *dir,
341 off_t offset);
344 SMBC_fstatdir_ctx(SMBCCTX *context,
345 SMBCFILE *dir,
346 struct stat *st);
349 SMBC_chmod_ctx(SMBCCTX *context,
350 const char *fname,
351 mode_t newmode);
354 SMBC_utimes_ctx(SMBCCTX *context,
355 const char *fname,
356 struct timeval *tbuf);
359 SMBC_unlink_ctx(SMBCCTX *context,
360 const char *fname);
363 SMBC_rename_ctx(SMBCCTX *ocontext,
364 const char *oname,
365 SMBCCTX *ncontext,
366 const char *nname);
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 */
376 SMBCFILE *
377 SMBC_open_ctx(SMBCCTX *context,
378 const char *fname,
379 int flags,
380 mode_t mode);
382 SMBCFILE *
383 SMBC_creat_ctx(SMBCCTX *context,
384 const char *path,
385 mode_t mode);
387 ssize_t
388 SMBC_read_ctx(SMBCCTX *context,
389 SMBCFILE *file,
390 void *buf,
391 size_t count);
393 ssize_t
394 SMBC_write_ctx(SMBCCTX *context,
395 SMBCFILE *file,
396 const void *buf,
397 size_t count);
399 off_t
400 SMBC_splice_ctx(SMBCCTX *context,
401 SMBCFILE *srcfile,
402 SMBCFILE *dstfile,
403 off_t count,
404 int (*splice_cb)(off_t n, void *priv),
405 void *priv);
408 SMBC_close_ctx(SMBCCTX *context,
409 SMBCFILE *file);
411 NTSTATUS
412 SMBC_getatr(SMBCCTX * context,
413 SMBCSRV *srv,
414 const char *path,
415 struct stat *sbuf);
417 bool
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,
423 uint16_t mode);
425 off_t
426 SMBC_lseek_ctx(SMBCCTX *context,
427 SMBCFILE *file,
428 off_t offset,
429 int whence);
432 SMBC_ftruncate_ctx(SMBCCTX *context,
433 SMBCFILE *file,
434 off_t length);
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,
443 SMBCCTX *context,
444 const char *fname,
445 char **pp_workgroup,
446 char **pp_server,
447 uint16_t *p_port,
448 char **pp_share,
449 char **pp_path,
450 char **pp_user,
451 char **pp_password,
452 char **pp_options);
455 /* Functions in libsmb_printjob.c */
456 SMBCFILE *
457 SMBC_open_print_job_ctx(SMBCCTX *context,
458 const char *fname);
461 SMBC_print_file_ctx(SMBCCTX *c_file,
462 const char *fname,
463 SMBCCTX *c_print,
464 const char *printq);
467 SMBC_list_print_jobs_ctx(SMBCCTX *context,
468 const char *fname,
469 smbc_list_print_job_fn fn);
472 SMBC_unlink_print_job_ctx(SMBCCTX *context,
473 const char *fname,
474 int id);
477 /* Functions in libsmb_server.c */
479 SMBC_check_server(SMBCCTX * context,
480 SMBCSRV * server);
483 SMBC_remove_unused_server(SMBCCTX * context,
484 SMBCSRV * srv);
486 void
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);
492 SMBCSRV *
493 SMBC_find_server(TALLOC_CTX *ctx,
494 SMBCCTX *context,
495 const char *server,
496 const char *share,
497 char **pp_workgroup,
498 char **pp_username,
499 char **pp_password);
501 SMBCSRV *
502 SMBC_server(TALLOC_CTX *ctx,
503 SMBCCTX *context,
504 bool connect_if_not_found,
505 const char *server,
506 uint16_t port,
507 const char *share,
508 char **pp_workgroup,
509 char **pp_username,
510 char **pp_password);
512 SMBCSRV *
513 SMBC_attr_server(TALLOC_CTX *ctx,
514 SMBCCTX *context,
515 const char *server,
516 uint16_t port,
517 const char *share,
518 char **pp_workgroup,
519 char **pp_username,
520 char **pp_password);
523 /* Functions in libsmb_stat.c */
524 void setup_stat(struct stat *st,
525 const char *fname,
526 off_t size,
527 int mode,
528 ino_t ino,
529 dev_t dev,
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,
534 const char *fname,
535 struct stat *st);
538 SMBC_stat_ctx(SMBCCTX *context,
539 const char *fname,
540 struct stat *st);
543 SMBC_fstat_ctx(SMBCCTX *context,
544 SMBCFILE *file,
545 struct stat *st);
549 SMBC_statvfs_ctx(SMBCCTX *context,
550 char *path,
551 struct statvfs *st);
555 SMBC_fstatvfs_ctx(SMBCCTX *context,
556 SMBCFILE *file,
557 struct statvfs *st);
560 /* Functions in libsmb_xattr.c */
562 SMBC_setxattr_ctx(SMBCCTX *context,
563 const char *fname,
564 const char *name,
565 const void *value,
566 size_t size,
567 int flags);
570 SMBC_getxattr_ctx(SMBCCTX *context,
571 const char *fname,
572 const char *name,
573 const void *value,
574 size_t size);
577 SMBC_removexattr_ctx(SMBCCTX *context,
578 const char *fname,
579 const char *name);
582 SMBC_listxattr_ctx(SMBCCTX *context,
583 const char *fname,
584 char *list,
585 size_t size);
588 #endif