auth/spnego: make use of GENSEC_UPDATE_IS_NTERROR() in gensec_spnego_create_negTokenI...
[Samba.git] / source3 / include / libsmb_internal.h
blob0e0045e8c0eb4d8d9f7efbf21f83eac1c63a3cba
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;
104 * cache of cli_state we opened cli_fd on.
105 * Due to DFS can be a subsidiary connection to srv->cli
107 struct cli_state *targetcli;
108 char *fname;
109 off_t offset;
110 struct _SMBCSRV *srv;
111 bool file;
112 struct smbc_dir_list *dir_list, *dir_end, *dir_next;
113 int dir_type, dir_error;
115 SMBCFILE *next, *prev;
120 * Context structure
122 struct SMBC_internal_data {
124 /* True when this handle is initialized */
125 bool initialized;
127 /* dirent pointer location */
128 struct smbc_dirent dirent;
130 * Leave room for any urlencoded filename and the comment field.
132 * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
133 * plus a couple of null terminators (one after the filename,
134 * one after the comment).
136 * According to <linux/limits.h>, NAME_MAX is 255. Is it longer
137 * anyplace else?
139 char _dirent_name[1024];
142 * server connection list
144 SMBCSRV * servers;
147 * open file/dir list
149 SMBCFILE * files;
152 * Support "Create Time" in get/set with the *xattr() functions, if
153 * true. This replaces the dos attribute strings C_TIME, A_TIME and
154 * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
155 * CREATE_TIME. Default is FALSE, i.e. to use the old-style shorter
156 * names and to not support CREATE time, for backward compatibility.
158 bool full_time_names;
161 * The share mode of a file being opened. To match POSIX semantics
162 * (and maintain backward compatibility), DENY_NONE is the default.
164 smbc_share_mode share_mode;
167 * Authentication function which includes the context. This will be
168 * used if set; otherwise context->callbacks.auth_fn() will be used.
170 smbc_get_auth_data_with_context_fn auth_fn_with_context;
173 * An opaque (to this library) user data handle which can be set
174 * and retrieved with smbc_option_set() and smbc_option_get().
176 void * user_data;
179 * Should we attempt UNIX smb encryption ?
180 * Set to 0 if we should never attempt, set to 1 if
181 * encryption requested, set to 2 if encryption required.
183 smbc_smb_encrypt_level smb_encryption_level;
186 * Should we request case sensitivity of file names?
188 bool case_sensitive;
191 * Auth info needed for DFS traversal.
194 struct user_auth_info *auth_info;
196 struct smbc_server_cache * server_cache;
198 /* POSIX emulation functions */
199 struct
201 #if 0 /* Left in libsmbclient.h for backward compatibility */
202 smbc_open_fn open_fn;
203 smbc_creat_fn creat_fn;
204 smbc_read_fn read_fn;
205 smbc_write_fn write_fn;
206 smbc_unlink_fn unlink_fn;
207 smbc_rename_fn rename_fn;
208 smbc_lseek_fn lseek_fn;
209 smbc_stat_fn stat_fn;
210 smbc_fstat_fn fstat_fn;
211 #endif
212 smbc_statvfs_fn statvfs_fn;
213 smbc_fstatvfs_fn fstatvfs_fn;
214 smbc_ftruncate_fn ftruncate_fn;
215 #if 0 /* Left in libsmbclient.h for backward compatibility */
216 smbc_close_fn close_fn;
217 smbc_opendir_fn opendir_fn;
218 smbc_closedir_fn closedir_fn;
219 smbc_readdir_fn readdir_fn;
220 smbc_getdents_fn getdents_fn;
221 smbc_mkdir_fn mkdir_fn;
222 smbc_rmdir_fn rmdir_fn;
223 smbc_telldir_fn telldir_fn;
224 smbc_lseekdir_fn lseekdir_fn;
225 smbc_fstatdir_fn fstatdir_fn;
226 smbc_chmod_fn chmod_fn;
227 smbc_utimes_fn utimes_fn;
228 smbc_setxattr_fn setxattr_fn;
229 smbc_getxattr_fn getxattr_fn;
230 smbc_removexattr_fn removexattr_fn;
231 smbc_listxattr_fn listxattr_fn;
232 #endif
233 } posix_emu;
235 #if 0 /* Left in libsmbclient.h for backward compatibility */
236 /* Printing-related functions */
237 struct
239 smbc_print_file_fn print_file_fn;
240 smbc_open_print_job_fn open_print_job_fn;
241 smbc_list_print_jobs_fn list_print_jobs_fn;
242 smbc_unlink_print_job_fn unlink_print_job_fn;
243 } printing;
244 #endif
246 /* SMB high-level functions */
247 struct
249 smbc_splice_fn splice_fn;
250 smbc_notify_fn notify_fn;
251 } smb;
253 uint16_t port;
256 /* Functions in libsmb_cache.c */
258 SMBC_add_cached_server(SMBCCTX * context,
259 SMBCSRV * newsrv,
260 const char * server,
261 const char * share,
262 const char * workgroup,
263 const char * username);
265 SMBCSRV *
266 SMBC_get_cached_server(SMBCCTX * context,
267 const char * server,
268 const char * share,
269 const char * workgroup,
270 const char * user);
273 SMBC_remove_cached_server(SMBCCTX * context,
274 SMBCSRV * server);
277 SMBC_purge_cached_servers(SMBCCTX * context);
280 /* Functions in libsmb_dir.c */
282 SMBC_check_options(char *server,
283 char *share,
284 char *path,
285 char *options);
287 SMBCFILE *
288 SMBC_opendir_ctx(SMBCCTX *context,
289 const char *fname);
292 SMBC_closedir_ctx(SMBCCTX *context,
293 SMBCFILE *dir);
295 struct smbc_dirent *
296 SMBC_readdir_ctx(SMBCCTX *context,
297 SMBCFILE *dir);
300 SMBC_getdents_ctx(SMBCCTX *context,
301 SMBCFILE *dir,
302 struct smbc_dirent *dirp,
303 int count);
306 SMBC_mkdir_ctx(SMBCCTX *context,
307 const char *fname,
308 mode_t mode);
311 SMBC_rmdir_ctx(SMBCCTX *context,
312 const char *fname);
314 off_t
315 SMBC_telldir_ctx(SMBCCTX *context,
316 SMBCFILE *dir);
319 SMBC_lseekdir_ctx(SMBCCTX *context,
320 SMBCFILE *dir,
321 off_t offset);
324 SMBC_fstatdir_ctx(SMBCCTX *context,
325 SMBCFILE *dir,
326 struct stat *st);
329 SMBC_chmod_ctx(SMBCCTX *context,
330 const char *fname,
331 mode_t newmode);
334 SMBC_utimes_ctx(SMBCCTX *context,
335 const char *fname,
336 struct timeval *tbuf);
339 SMBC_unlink_ctx(SMBCCTX *context,
340 const char *fname);
343 SMBC_rename_ctx(SMBCCTX *ocontext,
344 const char *oname,
345 SMBCCTX *ncontext,
346 const char *nname);
349 SMBC_notify_ctx(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive,
350 uint32_t completion_filter, unsigned callback_timeout_ms,
351 smbc_notify_callback_fn cb, void *private_data);
355 /* Functions in libsmb_file.c */
356 SMBCFILE *
357 SMBC_open_ctx(SMBCCTX *context,
358 const char *fname,
359 int flags,
360 mode_t mode);
362 SMBCFILE *
363 SMBC_creat_ctx(SMBCCTX *context,
364 const char *path,
365 mode_t mode);
367 ssize_t
368 SMBC_read_ctx(SMBCCTX *context,
369 SMBCFILE *file,
370 void *buf,
371 size_t count);
373 ssize_t
374 SMBC_write_ctx(SMBCCTX *context,
375 SMBCFILE *file,
376 const void *buf,
377 size_t count);
379 off_t
380 SMBC_splice_ctx(SMBCCTX *context,
381 SMBCFILE *srcfile,
382 SMBCFILE *dstfile,
383 off_t count,
384 int (*splice_cb)(off_t n, void *priv),
385 void *priv);
388 SMBC_close_ctx(SMBCCTX *context,
389 SMBCFILE *file);
391 bool
392 SMBC_getatr(SMBCCTX * context,
393 SMBCSRV *srv,
394 const char *path,
395 uint16_t *mode,
396 off_t *size,
397 struct timespec *create_time_ts,
398 struct timespec *access_time_ts,
399 struct timespec *write_time_ts,
400 struct timespec *change_time_ts,
401 SMB_INO_T *ino);
403 bool
404 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
405 time_t create_time,
406 time_t access_time,
407 time_t write_time,
408 time_t change_time,
409 uint16_t mode);
411 off_t
412 SMBC_lseek_ctx(SMBCCTX *context,
413 SMBCFILE *file,
414 off_t offset,
415 int whence);
418 SMBC_ftruncate_ctx(SMBCCTX *context,
419 SMBCFILE *file,
420 off_t length);
423 /* Functions in libsmb_misc.c */
425 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
428 SMBC_errno(SMBCCTX *context,
429 struct cli_state *c);
432 /* Functions in libsmb_path.c */
434 SMBC_parse_path(TALLOC_CTX *ctx,
435 SMBCCTX *context,
436 const char *fname,
437 char **pp_workgroup,
438 char **pp_server,
439 uint16_t *p_port,
440 char **pp_share,
441 char **pp_path,
442 char **pp_user,
443 char **pp_password,
444 char **pp_options);
447 /* Functions in libsmb_printjob.c */
448 SMBCFILE *
449 SMBC_open_print_job_ctx(SMBCCTX *context,
450 const char *fname);
453 SMBC_print_file_ctx(SMBCCTX *c_file,
454 const char *fname,
455 SMBCCTX *c_print,
456 const char *printq);
459 SMBC_list_print_jobs_ctx(SMBCCTX *context,
460 const char *fname,
461 smbc_list_print_job_fn fn);
464 SMBC_unlink_print_job_ctx(SMBCCTX *context,
465 const char *fname,
466 int id);
469 /* Functions in libsmb_server.c */
471 SMBC_check_server(SMBCCTX * context,
472 SMBCSRV * server);
475 SMBC_remove_unused_server(SMBCCTX * context,
476 SMBCSRV * srv);
478 void
479 SMBC_get_auth_data(const char *server, const char *share,
480 char *workgroup_buf, int workgroup_buf_len,
481 char *username_buf, int username_buf_len,
482 char *password_buf, int password_buf_len);
484 SMBCSRV *
485 SMBC_find_server(TALLOC_CTX *ctx,
486 SMBCCTX *context,
487 const char *server,
488 const char *share,
489 char **pp_workgroup,
490 char **pp_username,
491 char **pp_password);
493 SMBCSRV *
494 SMBC_server(TALLOC_CTX *ctx,
495 SMBCCTX *context,
496 bool connect_if_not_found,
497 const char *server,
498 uint16_t port,
499 const char *share,
500 char **pp_workgroup,
501 char **pp_username,
502 char **pp_password);
504 SMBCSRV *
505 SMBC_attr_server(TALLOC_CTX *ctx,
506 SMBCCTX *context,
507 const char *server,
508 uint16_t port,
509 const char *share,
510 char **pp_workgroup,
511 char **pp_username,
512 char **pp_password);
515 /* Functions in libsmb_stat.c */
517 SMBC_stat_ctx(SMBCCTX *context,
518 const char *fname,
519 struct stat *st);
522 SMBC_fstat_ctx(SMBCCTX *context,
523 SMBCFILE *file,
524 struct stat *st);
528 SMBC_statvfs_ctx(SMBCCTX *context,
529 char *path,
530 struct statvfs *st);
534 SMBC_fstatvfs_ctx(SMBCCTX *context,
535 SMBCFILE *file,
536 struct statvfs *st);
539 /* Functions in libsmb_xattr.c */
541 SMBC_setxattr_ctx(SMBCCTX *context,
542 const char *fname,
543 const char *name,
544 const void *value,
545 size_t size,
546 int flags);
549 SMBC_getxattr_ctx(SMBCCTX *context,
550 const char *fname,
551 const char *name,
552 const void *value,
553 size_t size);
556 SMBC_removexattr_ctx(SMBCCTX *context,
557 const char *fname,
558 const char *name);
561 SMBC_listxattr_ctx(SMBCCTX *context,
562 const char *fname,
563 char *list,
564 size_t size);
567 #endif