Modified revamp of the libsmbclient interface.
[Samba/bb.git] / source3 / include / libsmb_internal.h
blob555b6ac138bffe5ae5b0e1b7cb955c2c0e986294
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"
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 {
41 int mode;
42 SMB_OFF_T size;
43 time_t create_time;
44 time_t access_time;
45 time_t write_time;
46 time_t change_time;
47 SMB_INO_T inode;
48 } 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 ... */
66 #ifndef ENOTSUP
67 #define ENOTSUP EOPNOTSUPP
68 #endif
71 struct _SMBCSRV {
72 struct cli_state *cli;
73 dev_t dev;
74 bool no_pathinfo;
75 bool no_pathinfo2;
76 bool no_nt_session;
77 POLICY_HND pol;
79 SMBCSRV *next, *prev;
83 /*
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
94 */
95 struct _SMBCFILE {
96 int cli_fd;
97 char *fname;
98 SMB_OFF_T offset;
99 struct _SMBCSRV *srv;
100 bool file;
101 struct smbc_dir_list *dir_list, *dir_end, *dir_next;
102 int dir_type, dir_error;
104 SMBCFILE *next, *prev;
109 * Context structure
111 struct SMBC_internal_data {
113 /* True when this handle is initialized */
114 bool initialized;
116 #if 0 /* Left in libsmbclient.h for backward compatibility */
117 /* Netbios name used for making connections */
118 char * netbios_name;
120 /* Workgroup used for making connections */
121 char * workgroup;
123 /* Username used for making connections */
124 char * user;
126 /* Debug level */
127 int debug;
129 /* Connection timeout value */
130 int timeout;
131 #endif
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
142 * anyplace else?
144 char dirent[1024];
147 * server connection list
149 SMBCSRV * servers;
152 * open file/dir list
154 SMBCFILE * files;
157 * Log to standard error instead of the more typical standard output
159 bool debug_stderr;
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 * An opaque (to this library) user data handle which can be set
178 * and retrieved with smbc_option_set() and smbc_option_get().
180 void * user_data;
183 * Should we attempt UNIX smb encryption ?
184 * Set to 0 if we should never attempt, set to 1 if
185 * encryption requested, set to 2 if encryption required.
187 int smb_encryption_level;
190 * From how many local master browsers should the list of
191 * workgroups be retrieved? It can take up to 12 minutes or
192 * longer after a server becomes a local master browser, for
193 * it to have the entire browse list (the list of
194 * workgroups/domains) from an entire network. Since a client
195 * never knows which local master browser will be found first,
196 * the one which is found first and used to retrieve a browse
197 * list may have an incomplete or empty browse list. By
198 * requesting the browse list from multiple local master
199 * browsers, a more complete list can be generated. For small
200 * networks (few workgroups), it is recommended that this
201 * value be set to 0, causing the browse lists from all found
202 * local master browsers to be retrieved and merged. For
203 * networks with many workgroups, a suitable value for this
204 * variable is probably somewhere around 3. (Default: 3).
206 int browse_max_lmb_count;
209 * There is a difference in the desired return strings from
210 * smbc_readdir() depending upon whether the filenames are to
211 * be displayed to the user, or whether they are to be
212 * appended to the path name passed to smbc_opendir() to call
213 * a further smbc_ function (e.g. open the file with
214 * smbc_open()). In the former case, the filename should be
215 * in "human readable" form. In the latter case, the smbc_
216 * functions expect a URL which must be url-encoded. Those
217 * functions decode the URL. If, for example, smbc_readdir()
218 * returned a file name of "abc%20def.txt", passing a path
219 * with this file name attached to smbc_open() would cause
220 * smbc_open to attempt to open the file "abc def.txt" since
221 * the %20 is decoded into a space.
223 * Set this option to True if the names returned by
224 * smbc_readdir() should be url-encoded such that they can be
225 * passed back to another smbc_ call. Set it to False if the
226 * names returned by smbc_readdir() are to be presented to the
227 * user.
229 * For backwards compatibility, this option defaults to False.
231 bool urlencode_readdir_entries;
234 * Some Windows versions appear to have a limit to the number
235 * of concurrent SESSIONs and/or TREE CONNECTions. In
236 * one-shot programs (i.e. the program runs and then quickly
237 * ends, thereby shutting down all connections), it is
238 * probably reasonable to establish a new connection for each
239 * share. In long-running applications, the limitation can be
240 * avoided by using only a single connection to each server,
241 * and issuing a new TREE CONNECT when the share is accessed.
243 bool one_share_per_server;
245 #if 0 /* Left in libsmbclient.h (flags) for backward compatibility */
246 /* Kerberos-related flags */
247 bool use_kerberos;
248 bool fallback_after_kerberos;
250 /* Don't try to do automatic anonymous login */
251 bool no_auto_anonymous_login;
253 /* Server-related functions */
254 struct
256 smbc_get_auth_data_fn get_auth_data_fn;
257 smbc_check_server_fn check_server_fn;
258 smbc_remove_unused_server_fn remove_unused_server_fn;
259 } server;
261 /* Cache-related functions */
262 struct
264 struct smbc_server_cache * server_cache_data;
265 smbc_add_cached_srv_fn add_cached_server_fn;
266 smbc_get_cached_srv_fn get_cached_server_fn;
267 smbc_remove_cached_srv_fn remove_cached_server_fn;
268 smbc_purge_cached_srv_fn purge_cached_server_fn;
269 } cache;
270 #endif
272 /* POSIX emulation functions */
273 struct
275 #if 0 /* Left in libsmbclient.h for backward compatibility */
276 smbc_open_fn open_fn;
277 smbc_creat_fn creat_fn;
278 smbc_read_fn read_fn;
279 smbc_write_fn write_fn;
280 smbc_unlink_fn unlink_fn;
281 smbc_rename_fn rename_fn;
282 smbc_lseek_fn lseek_fn;
283 smbc_stat_fn stat_fn;
284 smbc_fstat_fn fstat_fn;
285 #endif
286 smbc_ftruncate_fn ftruncate_fn;
287 #if 0 /* Left in libsmbclient.h for backward compatibility */
288 smbc_close_fn close_fn;
289 smbc_opendir_fn opendir_fn;
290 smbc_closedir_fn closedir_fn;
291 smbc_readdir_fn readdir_fn;
292 smbc_getdents_fn getdents_fn;
293 smbc_mkdir_fn mkdir_fn;
294 smbc_rmdir_fn rmdir_fn;
295 smbc_telldir_fn telldir_fn;
296 smbc_lseekdir_fn lseekdir_fn;
297 smbc_fstatdir_fn fstatdir_fn;
298 smbc_chmod_fn chmod_fn;
299 smbc_utimes_fn utimes_fn;
300 smbc_setxattr_fn setxattr_fn;
301 smbc_getxattr_fn getxattr_fn;
302 smbc_removexattr_fn removexattr_fn;
303 smbc_listxattr_fn listxattr_fn;
304 #endif
305 } posix_emu;
307 #if 0 /* Left in libsmbclient.h for backward compatibility */
308 /* Printing-related functions */
309 struct
311 smbc_print_file_fn print_file_fn;
312 smbc_open_print_job_fn open_print_job_fn;
313 smbc_list_print_jobs_fn list_print_jobs_fn;
314 smbc_unlink_print_job_fn unlink_print_job_fn;
315 } printing;
316 #endif
318 #if 0 /* None available yet */
319 /* SMB high-level functions */
320 struct
322 } smb;
324 #endif
327 /* Functions in libsmb_cache.c */
329 SMBC_add_cached_server(SMBCCTX * context,
330 SMBCSRV * newsrv,
331 const char * server,
332 const char * share,
333 const char * workgroup,
334 const char * username);
336 SMBCSRV *
337 SMBC_get_cached_server(SMBCCTX * context,
338 const char * server,
339 const char * share,
340 const char * workgroup,
341 const char * user);
344 SMBC_remove_cached_server(SMBCCTX * context,
345 SMBCSRV * server);
348 SMBC_purge_cached_servers(SMBCCTX * context);
351 /* Functions in libsmb_dir.c */
353 SMBC_check_options(char *server,
354 char *share,
355 char *path,
356 char *options);
358 SMBCFILE *
359 SMBC_opendir_ctx(SMBCCTX *context,
360 const char *fname);
363 SMBC_closedir_ctx(SMBCCTX *context,
364 SMBCFILE *dir);
366 struct smbc_dirent *
367 SMBC_readdir_ctx(SMBCCTX *context,
368 SMBCFILE *dir);
371 SMBC_getdents_ctx(SMBCCTX *context,
372 SMBCFILE *dir,
373 struct smbc_dirent *dirp,
374 int count);
377 SMBC_mkdir_ctx(SMBCCTX *context,
378 const char *fname,
379 mode_t mode);
382 SMBC_rmdir_ctx(SMBCCTX *context,
383 const char *fname);
385 off_t
386 SMBC_telldir_ctx(SMBCCTX *context,
387 SMBCFILE *dir);
390 SMBC_lseekdir_ctx(SMBCCTX *context,
391 SMBCFILE *dir,
392 off_t offset);
395 SMBC_fstatdir_ctx(SMBCCTX *context,
396 SMBCFILE *dir,
397 struct stat *st);
400 SMBC_chmod_ctx(SMBCCTX *context,
401 const char *fname,
402 mode_t newmode);
405 SMBC_utimes_ctx(SMBCCTX *context,
406 const char *fname,
407 struct timeval *tbuf);
410 SMBC_unlink_ctx(SMBCCTX *context,
411 const char *fname);
414 SMBC_rename_ctx(SMBCCTX *ocontext,
415 const char *oname,
416 SMBCCTX *ncontext,
417 const char *nname);
420 /* Functions in libsmb_file.c */
421 SMBCFILE *
422 SMBC_open_ctx(SMBCCTX *context,
423 const char *fname,
424 int flags,
425 mode_t mode);
427 SMBCFILE *
428 SMBC_creat_ctx(SMBCCTX *context,
429 const char *path,
430 mode_t mode);
432 ssize_t
433 SMBC_read_ctx(SMBCCTX *context,
434 SMBCFILE *file,
435 void *buf,
436 size_t count);
438 ssize_t
439 SMBC_write_ctx(SMBCCTX *context,
440 SMBCFILE *file,
441 void *buf,
442 size_t count);
445 SMBC_close_ctx(SMBCCTX *context,
446 SMBCFILE *file);
448 bool
449 SMBC_getatr(SMBCCTX * context,
450 SMBCSRV *srv,
451 char *path,
452 uint16 *mode,
453 SMB_OFF_T *size,
454 struct timespec *create_time_ts,
455 struct timespec *access_time_ts,
456 struct timespec *write_time_ts,
457 struct timespec *change_time_ts,
458 SMB_INO_T *ino);
460 bool
461 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
462 time_t create_time,
463 time_t access_time,
464 time_t write_time,
465 time_t change_time,
466 uint16 mode);
468 off_t
469 SMBC_lseek_ctx(SMBCCTX *context,
470 SMBCFILE *file,
471 off_t offset,
472 int whence);
475 SMBC_ftruncate_ctx(SMBCCTX *context,
476 SMBCFILE *file,
477 off_t length);
480 /* Functions in libsmb_misc.c */
482 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
485 SMBC_errno(SMBCCTX *context,
486 struct cli_state *c);
489 /* Functions in libsmb_path.c */
491 SMBC_urldecode(char *dest,
492 char *src,
493 size_t max_dest_len);
496 SMBC_urlencode(char *dest,
497 char *src,
498 int max_dest_len);
501 SMBC_parse_path(TALLOC_CTX *ctx,
502 SMBCCTX *context,
503 const char *fname,
504 char **pp_workgroup,
505 char **pp_server,
506 char **pp_share,
507 char **pp_path,
508 char **pp_user,
509 char **pp_password,
510 char **pp_options);
513 /* Functions in libsmb_printjob.c */
514 SMBCFILE *
515 SMBC_open_print_job_ctx(SMBCCTX *context,
516 const char *fname);
519 SMBC_print_file_ctx(SMBCCTX *c_file,
520 const char *fname,
521 SMBCCTX *c_print,
522 const char *printq);
525 SMBC_list_print_jobs_ctx(SMBCCTX *context,
526 const char *fname,
527 smbc_list_print_job_fn fn);
530 SMBC_unlink_print_job_ctx(SMBCCTX *context,
531 const char *fname,
532 int id);
535 /* Functions in libsmb_server.c */
537 SMBC_check_server(SMBCCTX * context,
538 SMBCSRV * server);
541 SMBC_remove_unused_server(SMBCCTX * context,
542 SMBCSRV * srv);
544 void
545 SMBC_call_auth_fn(TALLOC_CTX *ctx,
546 SMBCCTX *context,
547 const char *server,
548 const char *share,
549 char **pp_workgroup,
550 char **pp_username,
551 char **pp_password);
553 void
554 SMBC_get_auth_data(const char *server, const char *share,
555 char *workgroup_buf, int workgroup_buf_len,
556 char *username_buf, int username_buf_len,
557 char *password_buf, int password_buf_len);
559 SMBCSRV *
560 SMBC_find_server(TALLOC_CTX *ctx,
561 SMBCCTX *context,
562 const char *server,
563 const char *share,
564 char **pp_workgroup,
565 char **pp_username,
566 char **pp_password);
568 SMBCSRV *
569 SMBC_server(TALLOC_CTX *ctx,
570 SMBCCTX *context,
571 bool connect_if_not_found,
572 const char *server,
573 const char *share,
574 char **pp_workgroup,
575 char **pp_username,
576 char **pp_password);
578 SMBCSRV *
579 SMBC_attr_server(TALLOC_CTX *ctx,
580 SMBCCTX *context,
581 const char *server,
582 const char *share,
583 char **pp_workgroup,
584 char **pp_username,
585 char **pp_password);
588 /* Functions in libsmb_stat.c */
590 SMBC_stat_ctx(SMBCCTX *context,
591 const char *fname,
592 struct stat *st);
595 SMBC_fstat_ctx(SMBCCTX *context,
596 SMBCFILE *file,
597 struct stat *st);
600 /* Functions in libsmb_xattr.c */
602 SMBC_setxattr_ctx(SMBCCTX *context,
603 const char *fname,
604 const char *name,
605 const void *value,
606 size_t size,
607 int flags);
610 SMBC_getxattr_ctx(SMBCCTX *context,
611 const char *fname,
612 const char *name,
613 const void *value,
614 size_t size);
617 SMBC_removexattr_ctx(SMBCCTX *context,
618 const char *fname,
619 const char *name);
622 SMBC_listxattr_ctx(SMBCCTX *context,
623 const char *fname,
624 char *list,
625 size_t size);
628 #endif