ldb_kv: Use ldb_msg_add_steal_value() in msg_add_distinguished_name()
[Samba.git] / source3 / include / libsmb_internal.h
blobf3e44e875d88bc0d9320bd10a9fb6b6fa2459046
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
35 #define SMBC_FILE_MODE (S_IFREG | 0444)
36 #define SMBC_DIR_MODE (S_IFDIR | 0555)
39 * DOS Attribute values (used internally)
41 typedef struct DOS_ATTR_DESC {
42 int mode;
43 off_t size;
44 time_t create_time;
45 time_t access_time;
46 time_t write_time;
47 time_t change_time;
48 SMB_INO_T inode;
49 } DOS_ATTR_DESC;
52 * Extension of libsmbclient.h's #defines
54 #define SMB_CTX_FLAG_USE_NT_HASH (1 << 4)
57 * Internal flags for extended attributes
60 /* internal mode values */
61 #define SMBC_XATTR_MODE_ADD 1
62 #define SMBC_XATTR_MODE_REMOVE 2
63 #define SMBC_XATTR_MODE_REMOVE_ALL 3
64 #define SMBC_XATTR_MODE_SET 4
65 #define SMBC_XATTR_MODE_CHOWN 5
66 #define SMBC_XATTR_MODE_CHGRP 6
68 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
70 /*We should test for this in configure ... */
71 #ifndef ENOTSUP
72 #define ENOTSUP EOPNOTSUPP
73 #endif
76 struct _SMBCSRV {
77 struct cli_state *cli;
78 dev_t dev;
79 bool no_pathinfo;
80 bool no_pathinfo2;
81 bool no_pathinfo3;
82 bool no_nt_session;
83 struct policy_handle pol;
84 time_t last_echo_time;
86 SMBCSRV *next, *prev;
90 * Keep directory entries in a list
92 struct smbc_dir_list {
93 struct smbc_dir_list *next;
94 struct smbc_dirent *dirent;
97 struct smbc_dirplus_list {
98 struct smbc_dirplus_list *next;
99 struct libsmb_file_info *smb_finfo;
103 * Structure for open file management
105 struct _SMBCFILE {
106 int cli_fd;
108 * cache of cli_state we opened cli_fd on.
109 * Due to DFS can be a subsidiary connection to srv->cli
111 struct cli_state *targetcli;
112 char *fname;
113 off_t offset;
114 struct _SMBCSRV *srv;
115 bool file;
116 struct smbc_dir_list *dir_list, *dir_end, *dir_next;
117 struct smbc_dirplus_list *dirplus_list, *dirplus_end, *dirplus_next;
118 int dir_type, dir_error;
120 SMBCFILE *next, *prev;
125 * Context structure
127 struct SMBC_internal_data {
129 /* True when this handle is initialized */
130 bool initialized;
132 /* dirent pointer location */
133 struct smbc_dirent dirent;
135 * Leave room for any urlencoded filename and the comment field.
137 * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
138 * plus a couple of null terminators (one after the filename,
139 * one after the comment).
141 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
142 * anyplace else?
144 char _dirent_name[1024];
147 * server connection list
149 SMBCSRV * servers;
152 * open file/dir list
154 SMBCFILE * files;
157 * Support "Create Time" in get/set with the *xattr() functions, if
158 * true. This replaces the dos attribute strings C_TIME, A_TIME and
159 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
160 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
161 * names and to not support CREATE time, for backward compatibility.
163 bool full_time_names;
166 * The share mode of a file being opened. To match POSIX semantics
167 * (and maintain backward compatibility), DENY_NONE is the default.
169 smbc_share_mode share_mode;
172 * Authentication function which includes the context. This will be
173 * used if set; otherwise context->callbacks.auth_fn() will be used.
175 smbc_get_auth_data_with_context_fn auth_fn_with_context;
178 * An opaque (to this library) user data handle which can be set
179 * and retrieved with smbc_option_set() and smbc_option_get().
181 void * user_data;
184 * Should we attempt UNIX smb encryption ?
185 * Set to 0 if we should never attempt, set to 1 if
186 * encryption requested, set to 2 if encryption required.
188 smbc_smb_encrypt_level smb_encryption_level;
191 * Should we request case sensitivity of file names?
193 bool case_sensitive;
196 * Auth info needed for DFS traversal.
199 struct user_auth_info *auth_info;
201 struct smbc_server_cache * server_cache;
203 /* POSIX emulation functions */
204 struct
206 #if 0 /* Left in libsmbclient.h for backward compatibility */
207 smbc_open_fn open_fn;
208 smbc_creat_fn creat_fn;
209 smbc_read_fn read_fn;
210 smbc_write_fn write_fn;
211 smbc_unlink_fn unlink_fn;
212 smbc_rename_fn rename_fn;
213 smbc_lseek_fn lseek_fn;
214 smbc_stat_fn stat_fn;
215 smbc_fstat_fn fstat_fn;
216 #endif
217 smbc_statvfs_fn statvfs_fn;
218 smbc_fstatvfs_fn fstatvfs_fn;
219 smbc_ftruncate_fn ftruncate_fn;
220 #if 0 /* Left in libsmbclient.h for backward compatibility */
221 smbc_close_fn close_fn;
222 smbc_opendir_fn opendir_fn;
223 smbc_closedir_fn closedir_fn;
224 smbc_readdir_fn readdir_fn;
225 smbc_getdents_fn getdents_fn;
226 smbc_mkdir_fn mkdir_fn;
227 smbc_rmdir_fn rmdir_fn;
228 smbc_telldir_fn telldir_fn;
229 smbc_lseekdir_fn lseekdir_fn;
230 smbc_fstatdir_fn fstatdir_fn;
231 smbc_chmod_fn chmod_fn;
232 smbc_utimes_fn utimes_fn;
233 smbc_setxattr_fn setxattr_fn;
234 smbc_getxattr_fn getxattr_fn;
235 smbc_removexattr_fn removexattr_fn;
236 smbc_listxattr_fn listxattr_fn;
237 #endif
238 } posix_emu;
240 #if 0 /* Left in libsmbclient.h for backward compatibility */
241 /* Printing-related functions */
242 struct
244 smbc_print_file_fn print_file_fn;
245 smbc_open_print_job_fn open_print_job_fn;
246 smbc_list_print_jobs_fn list_print_jobs_fn;
247 smbc_unlink_print_job_fn unlink_print_job_fn;
248 } printing;
249 #endif
251 /* SMB high-level functions */
252 struct
254 smbc_splice_fn splice_fn;
255 smbc_notify_fn notify_fn;
256 } smb;
258 uint16_t port;
261 /* Functions in libsmb_cache.c */
263 SMBC_add_cached_server(SMBCCTX * context,
264 SMBCSRV * newsrv,
265 const char * server,
266 const char * share,
267 const char * workgroup,
268 const char * username);
270 SMBCSRV *
271 SMBC_get_cached_server(SMBCCTX * context,
272 const char * server,
273 const char * share,
274 const char * workgroup,
275 const char * user);
278 SMBC_remove_cached_server(SMBCCTX * context,
279 SMBCSRV * server);
282 SMBC_purge_cached_servers(SMBCCTX * context);
285 /* Functions in libsmb_dir.c */
287 SMBC_check_options(char *server,
288 char *share,
289 char *path,
290 char *options);
292 SMBCFILE *
293 SMBC_opendir_ctx(SMBCCTX *context,
294 const char *fname);
297 SMBC_closedir_ctx(SMBCCTX *context,
298 SMBCFILE *dir);
300 struct smbc_dirent *
301 SMBC_readdir_ctx(SMBCCTX *context,
302 SMBCFILE *dir);
304 const struct libsmb_file_info *
305 SMBC_readdirplus_ctx(SMBCCTX *context,
306 SMBCFILE *dir);
309 SMBC_getdents_ctx(SMBCCTX *context,
310 SMBCFILE *dir,
311 struct smbc_dirent *dirp,
312 int count);
315 SMBC_mkdir_ctx(SMBCCTX *context,
316 const char *fname,
317 mode_t mode);
320 SMBC_rmdir_ctx(SMBCCTX *context,
321 const char *fname);
323 off_t
324 SMBC_telldir_ctx(SMBCCTX *context,
325 SMBCFILE *dir);
328 SMBC_lseekdir_ctx(SMBCCTX *context,
329 SMBCFILE *dir,
330 off_t offset);
333 SMBC_fstatdir_ctx(SMBCCTX *context,
334 SMBCFILE *dir,
335 struct stat *st);
338 SMBC_chmod_ctx(SMBCCTX *context,
339 const char *fname,
340 mode_t newmode);
343 SMBC_utimes_ctx(SMBCCTX *context,
344 const char *fname,
345 struct timeval *tbuf);
348 SMBC_unlink_ctx(SMBCCTX *context,
349 const char *fname);
352 SMBC_rename_ctx(SMBCCTX *ocontext,
353 const char *oname,
354 SMBCCTX *ncontext,
355 const char *nname);
358 SMBC_notify_ctx(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive,
359 uint32_t completion_filter, unsigned callback_timeout_ms,
360 smbc_notify_callback_fn cb, void *private_data);
364 /* Functions in libsmb_file.c */
365 SMBCFILE *
366 SMBC_open_ctx(SMBCCTX *context,
367 const char *fname,
368 int flags,
369 mode_t mode);
371 SMBCFILE *
372 SMBC_creat_ctx(SMBCCTX *context,
373 const char *path,
374 mode_t mode);
376 ssize_t
377 SMBC_read_ctx(SMBCCTX *context,
378 SMBCFILE *file,
379 void *buf,
380 size_t count);
382 ssize_t
383 SMBC_write_ctx(SMBCCTX *context,
384 SMBCFILE *file,
385 const void *buf,
386 size_t count);
388 off_t
389 SMBC_splice_ctx(SMBCCTX *context,
390 SMBCFILE *srcfile,
391 SMBCFILE *dstfile,
392 off_t count,
393 int (*splice_cb)(off_t n, void *priv),
394 void *priv);
397 SMBC_close_ctx(SMBCCTX *context,
398 SMBCFILE *file);
400 bool
401 SMBC_getatr(SMBCCTX * context,
402 SMBCSRV *srv,
403 const char *path,
404 uint16_t *mode,
405 off_t *size,
406 struct timespec *create_time_ts,
407 struct timespec *access_time_ts,
408 struct timespec *write_time_ts,
409 struct timespec *change_time_ts,
410 SMB_INO_T *ino);
412 bool
413 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
414 time_t create_time,
415 time_t access_time,
416 time_t write_time,
417 time_t change_time,
418 uint16_t mode);
420 off_t
421 SMBC_lseek_ctx(SMBCCTX *context,
422 SMBCFILE *file,
423 off_t offset,
424 int whence);
427 SMBC_ftruncate_ctx(SMBCCTX *context,
428 SMBCFILE *file,
429 off_t length);
432 /* Functions in libsmb_misc.c */
434 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
437 SMBC_errno(SMBCCTX *context,
438 struct cli_state *c);
441 /* Functions in libsmb_path.c */
443 SMBC_parse_path(TALLOC_CTX *ctx,
444 SMBCCTX *context,
445 const char *fname,
446 char **pp_workgroup,
447 char **pp_server,
448 uint16_t *p_port,
449 char **pp_share,
450 char **pp_path,
451 char **pp_user,
452 char **pp_password,
453 char **pp_options);
456 /* Functions in libsmb_printjob.c */
457 SMBCFILE *
458 SMBC_open_print_job_ctx(SMBCCTX *context,
459 const char *fname);
462 SMBC_print_file_ctx(SMBCCTX *c_file,
463 const char *fname,
464 SMBCCTX *c_print,
465 const char *printq);
468 SMBC_list_print_jobs_ctx(SMBCCTX *context,
469 const char *fname,
470 smbc_list_print_job_fn fn);
473 SMBC_unlink_print_job_ctx(SMBCCTX *context,
474 const char *fname,
475 int id);
478 /* Functions in libsmb_server.c */
480 SMBC_check_server(SMBCCTX * context,
481 SMBCSRV * server);
484 SMBC_remove_unused_server(SMBCCTX * context,
485 SMBCSRV * srv);
487 void
488 SMBC_get_auth_data(const char *server, const char *share,
489 char *workgroup_buf, int workgroup_buf_len,
490 char *username_buf, int username_buf_len,
491 char *password_buf, int password_buf_len);
493 SMBCSRV *
494 SMBC_find_server(TALLOC_CTX *ctx,
495 SMBCCTX *context,
496 const char *server,
497 const char *share,
498 char **pp_workgroup,
499 char **pp_username,
500 char **pp_password);
502 SMBCSRV *
503 SMBC_server(TALLOC_CTX *ctx,
504 SMBCCTX *context,
505 bool connect_if_not_found,
506 const char *server,
507 uint16_t port,
508 const char *share,
509 char **pp_workgroup,
510 char **pp_username,
511 char **pp_password);
513 SMBCSRV *
514 SMBC_attr_server(TALLOC_CTX *ctx,
515 SMBCCTX *context,
516 const char *server,
517 uint16_t port,
518 const char *share,
519 char **pp_workgroup,
520 char **pp_username,
521 char **pp_password);
524 /* Functions in libsmb_stat.c */
526 SMBC_stat_ctx(SMBCCTX *context,
527 const char *fname,
528 struct stat *st);
531 SMBC_fstat_ctx(SMBCCTX *context,
532 SMBCFILE *file,
533 struct stat *st);
537 SMBC_statvfs_ctx(SMBCCTX *context,
538 char *path,
539 struct statvfs *st);
543 SMBC_fstatvfs_ctx(SMBCCTX *context,
544 SMBCFILE *file,
545 struct statvfs *st);
548 /* Functions in libsmb_xattr.c */
550 SMBC_setxattr_ctx(SMBCCTX *context,
551 const char *fname,
552 const char *name,
553 const void *value,
554 size_t size,
555 int flags);
558 SMBC_getxattr_ctx(SMBCCTX *context,
559 const char *fname,
560 const char *name,
561 const void *value,
562 size_t size);
565 SMBC_removexattr_ctx(SMBCCTX *context,
566 const char *fname,
567 const char *name);
570 SMBC_listxattr_ctx(SMBCCTX *context,
571 const char *fname,
572 char *list,
573 size_t size);
576 #endif