s3: lib: libsmbclient: If reusing a server struct, check every cli->timout milisecond...
[Samba.git] / source3 / include / libsmb_internal.h
blob65fad99892b67f11f5c581a88994a168c40ca58f
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;
99 * Structure for open file management
101 struct _SMBCFILE {
102 int cli_fd;
103 char *fname;
104 off_t offset;
105 struct _SMBCSRV *srv;
106 bool file;
107 struct smbc_dir_list *dir_list, *dir_end, *dir_next;
108 int dir_type, dir_error;
110 SMBCFILE *next, *prev;
115 * Context structure
117 struct SMBC_internal_data {
119 /* True when this handle is initialized */
120 bool initialized;
122 /* dirent pointer location */
123 struct smbc_dirent dirent;
125 * Leave room for any urlencoded filename and the comment field.
127 * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
128 * plus a couple of null terminators (one after the filename,
129 * one after the comment).
131 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
132 * anyplace else?
134 char _dirent_name[1024];
137 * server connection list
139 SMBCSRV * servers;
142 * open file/dir list
144 SMBCFILE * files;
147 * Support "Create Time" in get/set with the *xattr() functions, if
148 * true. This replaces the dos attribute strings C_TIME, A_TIME and
149 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
150 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
151 * names and to not support CREATE time, for backward compatibility.
153 bool full_time_names;
156 * The share mode of a file being opened. To match POSIX semantics
157 * (and maintain backward compatibility), DENY_NONE is the default.
159 smbc_share_mode share_mode;
162 * Authentication function which includes the context. This will be
163 * used if set; otherwise context->callbacks.auth_fn() will be used.
165 smbc_get_auth_data_with_context_fn auth_fn_with_context;
168 * An opaque (to this library) user data handle which can be set
169 * and retrieved with smbc_option_set() and smbc_option_get().
171 void * user_data;
174 * Should we attempt UNIX smb encryption ?
175 * Set to 0 if we should never attempt, set to 1 if
176 * encryption requested, set to 2 if encryption required.
178 smbc_smb_encrypt_level smb_encryption_level;
181 * Should we request case sensitivity of file names?
183 bool case_sensitive;
186 * Auth info needed for DFS traversal.
189 struct user_auth_info *auth_info;
191 struct smbc_server_cache * server_cache;
193 /* POSIX emulation functions */
194 struct
196 #if 0 /* Left in libsmbclient.h for backward compatibility */
197 smbc_open_fn open_fn;
198 smbc_creat_fn creat_fn;
199 smbc_read_fn read_fn;
200 smbc_write_fn write_fn;
201 smbc_unlink_fn unlink_fn;
202 smbc_rename_fn rename_fn;
203 smbc_lseek_fn lseek_fn;
204 smbc_stat_fn stat_fn;
205 smbc_fstat_fn fstat_fn;
206 #endif
207 smbc_statvfs_fn statvfs_fn;
208 smbc_fstatvfs_fn fstatvfs_fn;
209 smbc_ftruncate_fn ftruncate_fn;
210 #if 0 /* Left in libsmbclient.h for backward compatibility */
211 smbc_close_fn close_fn;
212 smbc_opendir_fn opendir_fn;
213 smbc_closedir_fn closedir_fn;
214 smbc_readdir_fn readdir_fn;
215 smbc_getdents_fn getdents_fn;
216 smbc_mkdir_fn mkdir_fn;
217 smbc_rmdir_fn rmdir_fn;
218 smbc_telldir_fn telldir_fn;
219 smbc_lseekdir_fn lseekdir_fn;
220 smbc_fstatdir_fn fstatdir_fn;
221 smbc_chmod_fn chmod_fn;
222 smbc_utimes_fn utimes_fn;
223 smbc_setxattr_fn setxattr_fn;
224 smbc_getxattr_fn getxattr_fn;
225 smbc_removexattr_fn removexattr_fn;
226 smbc_listxattr_fn listxattr_fn;
227 #endif
228 } posix_emu;
230 #if 0 /* Left in libsmbclient.h for backward compatibility */
231 /* Printing-related functions */
232 struct
234 smbc_print_file_fn print_file_fn;
235 smbc_open_print_job_fn open_print_job_fn;
236 smbc_list_print_jobs_fn list_print_jobs_fn;
237 smbc_unlink_print_job_fn unlink_print_job_fn;
238 } printing;
239 #endif
241 #if 0 /* None available yet */
242 /* SMB high-level functions */
243 struct
245 } smb;
247 #endif
248 uint16_t port;
251 /* Functions in libsmb_cache.c */
253 SMBC_add_cached_server(SMBCCTX * context,
254 SMBCSRV * newsrv,
255 const char * server,
256 const char * share,
257 const char * workgroup,
258 const char * username);
260 SMBCSRV *
261 SMBC_get_cached_server(SMBCCTX * context,
262 const char * server,
263 const char * share,
264 const char * workgroup,
265 const char * user);
268 SMBC_remove_cached_server(SMBCCTX * context,
269 SMBCSRV * server);
272 SMBC_purge_cached_servers(SMBCCTX * context);
275 /* Functions in libsmb_dir.c */
277 SMBC_check_options(char *server,
278 char *share,
279 char *path,
280 char *options);
282 SMBCFILE *
283 SMBC_opendir_ctx(SMBCCTX *context,
284 const char *fname);
287 SMBC_closedir_ctx(SMBCCTX *context,
288 SMBCFILE *dir);
290 struct smbc_dirent *
291 SMBC_readdir_ctx(SMBCCTX *context,
292 SMBCFILE *dir);
295 SMBC_getdents_ctx(SMBCCTX *context,
296 SMBCFILE *dir,
297 struct smbc_dirent *dirp,
298 int count);
301 SMBC_mkdir_ctx(SMBCCTX *context,
302 const char *fname,
303 mode_t mode);
306 SMBC_rmdir_ctx(SMBCCTX *context,
307 const char *fname);
309 off_t
310 SMBC_telldir_ctx(SMBCCTX *context,
311 SMBCFILE *dir);
314 SMBC_lseekdir_ctx(SMBCCTX *context,
315 SMBCFILE *dir,
316 off_t offset);
319 SMBC_fstatdir_ctx(SMBCCTX *context,
320 SMBCFILE *dir,
321 struct stat *st);
324 SMBC_chmod_ctx(SMBCCTX *context,
325 const char *fname,
326 mode_t newmode);
329 SMBC_utimes_ctx(SMBCCTX *context,
330 const char *fname,
331 struct timeval *tbuf);
334 SMBC_unlink_ctx(SMBCCTX *context,
335 const char *fname);
338 SMBC_rename_ctx(SMBCCTX *ocontext,
339 const char *oname,
340 SMBCCTX *ncontext,
341 const char *nname);
344 /* Functions in libsmb_file.c */
345 SMBCFILE *
346 SMBC_open_ctx(SMBCCTX *context,
347 const char *fname,
348 int flags,
349 mode_t mode);
351 SMBCFILE *
352 SMBC_creat_ctx(SMBCCTX *context,
353 const char *path,
354 mode_t mode);
356 ssize_t
357 SMBC_read_ctx(SMBCCTX *context,
358 SMBCFILE *file,
359 void *buf,
360 size_t count);
362 ssize_t
363 SMBC_write_ctx(SMBCCTX *context,
364 SMBCFILE *file,
365 const void *buf,
366 size_t count);
369 SMBC_close_ctx(SMBCCTX *context,
370 SMBCFILE *file);
372 bool
373 SMBC_getatr(SMBCCTX * context,
374 SMBCSRV *srv,
375 const char *path,
376 uint16 *mode,
377 off_t *size,
378 struct timespec *create_time_ts,
379 struct timespec *access_time_ts,
380 struct timespec *write_time_ts,
381 struct timespec *change_time_ts,
382 SMB_INO_T *ino);
384 bool
385 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
386 time_t create_time,
387 time_t access_time,
388 time_t write_time,
389 time_t change_time,
390 uint16 mode);
392 off_t
393 SMBC_lseek_ctx(SMBCCTX *context,
394 SMBCFILE *file,
395 off_t offset,
396 int whence);
399 SMBC_ftruncate_ctx(SMBCCTX *context,
400 SMBCFILE *file,
401 off_t length);
404 /* Functions in libsmb_misc.c */
406 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
409 SMBC_errno(SMBCCTX *context,
410 struct cli_state *c);
413 /* Functions in libsmb_path.c */
415 SMBC_parse_path(TALLOC_CTX *ctx,
416 SMBCCTX *context,
417 const char *fname,
418 char **pp_workgroup,
419 char **pp_server,
420 uint16_t *p_port,
421 char **pp_share,
422 char **pp_path,
423 char **pp_user,
424 char **pp_password,
425 char **pp_options);
428 /* Functions in libsmb_printjob.c */
429 SMBCFILE *
430 SMBC_open_print_job_ctx(SMBCCTX *context,
431 const char *fname);
434 SMBC_print_file_ctx(SMBCCTX *c_file,
435 const char *fname,
436 SMBCCTX *c_print,
437 const char *printq);
440 SMBC_list_print_jobs_ctx(SMBCCTX *context,
441 const char *fname,
442 smbc_list_print_job_fn fn);
445 SMBC_unlink_print_job_ctx(SMBCCTX *context,
446 const char *fname,
447 int id);
450 /* Functions in libsmb_server.c */
452 SMBC_check_server(SMBCCTX * context,
453 SMBCSRV * server);
456 SMBC_remove_unused_server(SMBCCTX * context,
457 SMBCSRV * srv);
459 void
460 SMBC_get_auth_data(const char *server, const char *share,
461 char *workgroup_buf, int workgroup_buf_len,
462 char *username_buf, int username_buf_len,
463 char *password_buf, int password_buf_len);
465 SMBCSRV *
466 SMBC_find_server(TALLOC_CTX *ctx,
467 SMBCCTX *context,
468 const char *server,
469 const char *share,
470 char **pp_workgroup,
471 char **pp_username,
472 char **pp_password);
474 SMBCSRV *
475 SMBC_server(TALLOC_CTX *ctx,
476 SMBCCTX *context,
477 bool connect_if_not_found,
478 const char *server,
479 uint16_t port,
480 const char *share,
481 char **pp_workgroup,
482 char **pp_username,
483 char **pp_password);
485 SMBCSRV *
486 SMBC_attr_server(TALLOC_CTX *ctx,
487 SMBCCTX *context,
488 const char *server,
489 uint16_t port,
490 const char *share,
491 char **pp_workgroup,
492 char **pp_username,
493 char **pp_password);
496 /* Functions in libsmb_stat.c */
498 SMBC_stat_ctx(SMBCCTX *context,
499 const char *fname,
500 struct stat *st);
503 SMBC_fstat_ctx(SMBCCTX *context,
504 SMBCFILE *file,
505 struct stat *st);
509 SMBC_statvfs_ctx(SMBCCTX *context,
510 char *path,
511 struct statvfs *st);
515 SMBC_fstatvfs_ctx(SMBCCTX *context,
516 SMBCFILE *file,
517 struct statvfs *st);
520 /* Functions in libsmb_xattr.c */
522 SMBC_setxattr_ctx(SMBCCTX *context,
523 const char *fname,
524 const char *name,
525 const void *value,
526 size_t size,
527 int flags);
530 SMBC_getxattr_ctx(SMBCCTX *context,
531 const char *fname,
532 const char *name,
533 const void *value,
534 size_t size);
537 SMBC_removexattr_ctx(SMBCCTX *context,
538 const char *fname,
539 const char *name);
542 SMBC_listxattr_ctx(SMBCCTX *context,
543 const char *fname,
544 char *list,
545 size_t size);
548 #endif