s3: Survive an idle child that was killed
[Samba.git] / source3 / include / libsmb_internal.h
blob39a32f99fb1142bdcf5fd976be4c8f09dc6643f5
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 struct policy_handle 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 /* dirent pointer location */
117 struct smbc_dirent dirent;
119 * Leave room for any urlencoded filename and the comment field.
121 * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
122 * plus a couple of null terminators (one after the filename,
123 * one after the comment).
125 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
126 * anyplace else?
128 char _dirent_name[1024];
131 * server connection list
133 SMBCSRV * servers;
136 * open file/dir list
138 SMBCFILE * files;
141 * Support "Create Time" in get/set with the *xattr() functions, if
142 * true. This replaces the dos attribute strings C_TIME, A_TIME and
143 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
144 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
145 * names and to not support CREATE time, for backward compatibility.
147 bool full_time_names;
150 * The share mode of a file being opened. To match POSIX semantics
151 * (and maintain backward compatibility), DENY_NONE is the default.
153 smbc_share_mode share_mode;
156 * Authentication function which includes the context. This will be
157 * used if set; otherwise context->callbacks.auth_fn() will be used.
159 smbc_get_auth_data_with_context_fn auth_fn_with_context;
162 * An opaque (to this library) user data handle which can be set
163 * and retrieved with smbc_option_set() and smbc_option_get().
165 void * user_data;
168 * Should we attempt UNIX smb encryption ?
169 * Set to 0 if we should never attempt, set to 1 if
170 * encryption requested, set to 2 if encryption required.
172 smbc_smb_encrypt_level smb_encryption_level;
175 * Should we request case sensitivity of file names?
177 bool case_sensitive;
180 * Auth info needed for DFS traversal.
183 struct user_auth_info *auth_info;
185 struct smbc_server_cache * server_cache;
187 /* POSIX emulation functions */
188 struct
190 #if 0 /* Left in libsmbclient.h for backward compatibility */
191 smbc_open_fn open_fn;
192 smbc_creat_fn creat_fn;
193 smbc_read_fn read_fn;
194 smbc_write_fn write_fn;
195 smbc_unlink_fn unlink_fn;
196 smbc_rename_fn rename_fn;
197 smbc_lseek_fn lseek_fn;
198 smbc_stat_fn stat_fn;
199 smbc_fstat_fn fstat_fn;
200 #endif
201 smbc_statvfs_fn statvfs_fn;
202 smbc_fstatvfs_fn fstatvfs_fn;
203 smbc_ftruncate_fn ftruncate_fn;
204 #if 0 /* Left in libsmbclient.h for backward compatibility */
205 smbc_close_fn close_fn;
206 smbc_opendir_fn opendir_fn;
207 smbc_closedir_fn closedir_fn;
208 smbc_readdir_fn readdir_fn;
209 smbc_getdents_fn getdents_fn;
210 smbc_mkdir_fn mkdir_fn;
211 smbc_rmdir_fn rmdir_fn;
212 smbc_telldir_fn telldir_fn;
213 smbc_lseekdir_fn lseekdir_fn;
214 smbc_fstatdir_fn fstatdir_fn;
215 smbc_chmod_fn chmod_fn;
216 smbc_utimes_fn utimes_fn;
217 smbc_setxattr_fn setxattr_fn;
218 smbc_getxattr_fn getxattr_fn;
219 smbc_removexattr_fn removexattr_fn;
220 smbc_listxattr_fn listxattr_fn;
221 #endif
222 } posix_emu;
224 #if 0 /* Left in libsmbclient.h for backward compatibility */
225 /* Printing-related functions */
226 struct
228 smbc_print_file_fn print_file_fn;
229 smbc_open_print_job_fn open_print_job_fn;
230 smbc_list_print_jobs_fn list_print_jobs_fn;
231 smbc_unlink_print_job_fn unlink_print_job_fn;
232 } printing;
233 #endif
235 #if 0 /* None available yet */
236 /* SMB high-level functions */
237 struct
239 } smb;
241 #endif
244 /* Functions in libsmb_cache.c */
246 SMBC_add_cached_server(SMBCCTX * context,
247 SMBCSRV * newsrv,
248 const char * server,
249 const char * share,
250 const char * workgroup,
251 const char * username);
253 SMBCSRV *
254 SMBC_get_cached_server(SMBCCTX * context,
255 const char * server,
256 const char * share,
257 const char * workgroup,
258 const char * user);
261 SMBC_remove_cached_server(SMBCCTX * context,
262 SMBCSRV * server);
265 SMBC_purge_cached_servers(SMBCCTX * context);
268 /* Functions in libsmb_dir.c */
270 SMBC_check_options(char *server,
271 char *share,
272 char *path,
273 char *options);
275 SMBCFILE *
276 SMBC_opendir_ctx(SMBCCTX *context,
277 const char *fname);
280 SMBC_closedir_ctx(SMBCCTX *context,
281 SMBCFILE *dir);
283 struct smbc_dirent *
284 SMBC_readdir_ctx(SMBCCTX *context,
285 SMBCFILE *dir);
288 SMBC_getdents_ctx(SMBCCTX *context,
289 SMBCFILE *dir,
290 struct smbc_dirent *dirp,
291 int count);
294 SMBC_mkdir_ctx(SMBCCTX *context,
295 const char *fname,
296 mode_t mode);
299 SMBC_rmdir_ctx(SMBCCTX *context,
300 const char *fname);
302 off_t
303 SMBC_telldir_ctx(SMBCCTX *context,
304 SMBCFILE *dir);
307 SMBC_lseekdir_ctx(SMBCCTX *context,
308 SMBCFILE *dir,
309 off_t offset);
312 SMBC_fstatdir_ctx(SMBCCTX *context,
313 SMBCFILE *dir,
314 struct stat *st);
317 SMBC_chmod_ctx(SMBCCTX *context,
318 const char *fname,
319 mode_t newmode);
322 SMBC_utimes_ctx(SMBCCTX *context,
323 const char *fname,
324 struct timeval *tbuf);
327 SMBC_unlink_ctx(SMBCCTX *context,
328 const char *fname);
331 SMBC_rename_ctx(SMBCCTX *ocontext,
332 const char *oname,
333 SMBCCTX *ncontext,
334 const char *nname);
337 /* Functions in libsmb_file.c */
338 SMBCFILE *
339 SMBC_open_ctx(SMBCCTX *context,
340 const char *fname,
341 int flags,
342 mode_t mode);
344 SMBCFILE *
345 SMBC_creat_ctx(SMBCCTX *context,
346 const char *path,
347 mode_t mode);
349 ssize_t
350 SMBC_read_ctx(SMBCCTX *context,
351 SMBCFILE *file,
352 void *buf,
353 size_t count);
355 ssize_t
356 SMBC_write_ctx(SMBCCTX *context,
357 SMBCFILE *file,
358 const void *buf,
359 size_t count);
362 SMBC_close_ctx(SMBCCTX *context,
363 SMBCFILE *file);
365 bool
366 SMBC_getatr(SMBCCTX * context,
367 SMBCSRV *srv,
368 char *path,
369 uint16 *mode,
370 SMB_OFF_T *size,
371 struct timespec *create_time_ts,
372 struct timespec *access_time_ts,
373 struct timespec *write_time_ts,
374 struct timespec *change_time_ts,
375 SMB_INO_T *ino);
377 bool
378 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
379 time_t create_time,
380 time_t access_time,
381 time_t write_time,
382 time_t change_time,
383 uint16 mode);
385 off_t
386 SMBC_lseek_ctx(SMBCCTX *context,
387 SMBCFILE *file,
388 off_t offset,
389 int whence);
392 SMBC_ftruncate_ctx(SMBCCTX *context,
393 SMBCFILE *file,
394 off_t length);
397 /* Functions in libsmb_misc.c */
399 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
402 SMBC_errno(SMBCCTX *context,
403 struct cli_state *c);
406 /* Functions in libsmb_path.c */
408 SMBC_parse_path(TALLOC_CTX *ctx,
409 SMBCCTX *context,
410 const char *fname,
411 char **pp_workgroup,
412 char **pp_server,
413 char **pp_share,
414 char **pp_path,
415 char **pp_user,
416 char **pp_password,
417 char **pp_options);
420 /* Functions in libsmb_printjob.c */
421 SMBCFILE *
422 SMBC_open_print_job_ctx(SMBCCTX *context,
423 const char *fname);
426 SMBC_print_file_ctx(SMBCCTX *c_file,
427 const char *fname,
428 SMBCCTX *c_print,
429 const char *printq);
432 SMBC_list_print_jobs_ctx(SMBCCTX *context,
433 const char *fname,
434 smbc_list_print_job_fn fn);
437 SMBC_unlink_print_job_ctx(SMBCCTX *context,
438 const char *fname,
439 int id);
442 /* Functions in libsmb_server.c */
444 SMBC_check_server(SMBCCTX * context,
445 SMBCSRV * server);
448 SMBC_remove_unused_server(SMBCCTX * context,
449 SMBCSRV * srv);
451 void
452 SMBC_call_auth_fn(TALLOC_CTX *ctx,
453 SMBCCTX *context,
454 const char *server,
455 const char *share,
456 char **pp_workgroup,
457 char **pp_username,
458 char **pp_password);
460 void
461 SMBC_get_auth_data(const char *server, const char *share,
462 char *workgroup_buf, int workgroup_buf_len,
463 char *username_buf, int username_buf_len,
464 char *password_buf, int password_buf_len);
466 SMBCSRV *
467 SMBC_find_server(TALLOC_CTX *ctx,
468 SMBCCTX *context,
469 const char *server,
470 const char *share,
471 char **pp_workgroup,
472 char **pp_username,
473 char **pp_password);
475 SMBCSRV *
476 SMBC_server(TALLOC_CTX *ctx,
477 SMBCCTX *context,
478 bool connect_if_not_found,
479 const char *server,
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 const char *share,
490 char **pp_workgroup,
491 char **pp_username,
492 char **pp_password);
495 /* Functions in libsmb_stat.c */
497 SMBC_stat_ctx(SMBCCTX *context,
498 const char *fname,
499 struct stat *st);
502 SMBC_fstat_ctx(SMBCCTX *context,
503 SMBCFILE *file,
504 struct stat *st);
508 SMBC_statvfs_ctx(SMBCCTX *context,
509 char *path,
510 struct statvfs *st);
514 SMBC_fstatvfs_ctx(SMBCCTX *context,
515 SMBCFILE *file,
516 struct statvfs *st);
519 /* Functions in libsmb_xattr.c */
521 SMBC_setxattr_ctx(SMBCCTX *context,
522 const char *fname,
523 const char *name,
524 const void *value,
525 size_t size,
526 int flags);
529 SMBC_getxattr_ctx(SMBCCTX *context,
530 const char *fname,
531 const char *name,
532 const void *value,
533 size_t size);
536 SMBC_removexattr_ctx(SMBCCTX *context,
537 const char *fname,
538 const char *name);
541 SMBC_listxattr_ctx(SMBCCTX *context,
542 const char *fname,
543 char *list,
544 size_t size);
547 #endif