smbd/winbindd: Do an early check if ctdbd is functional
[mat/samba.git] / source3 / include / libsmb_internal.h
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
10
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.
15
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.
20
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/>.
23 */
24
25 #include "includes.h"
26
27
28 #ifndef _LIBSMB_INTERNAL_H_
29 #define _LIBSMB_INTERNAL_H_
30
31 #include "../include/libsmbclient.h"
32 #include "libsmb/clirap.h"
33
34 #define SMBC_MAX_NAME  1023
35 #define SMBC_FILE_MODE (S_IFREG | 0444)
36 #define SMBC_DIR_MODE  (S_IFDIR | 0555)
37
38 /*
39  * DOS Attribute values (used internally)
40  */
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;
50
51 /*
52  * Extension of libsmbclient.h's #defines
53  */
54 #define SMB_CTX_FLAG_USE_NT_HASH (1 << 4)
55
56 /*
57  * Internal flags for extended attributes
58  */
59
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
67
68 #define CREATE_ACCESS_READ      READ_CONTROL_ACCESS
69
70 /*We should test for this in configure ... */
71 #ifndef ENOTSUP
72 #define ENOTSUP EOPNOTSUPP
73 #endif
74
75
76 struct _SMBCSRV {
77         struct cli_state *cli;
78         dev_t dev;
79         bool no_pathinfo;
80         bool no_pathinfo2;
81         bool no_nt_session;
82         struct policy_handle pol;
83
84         SMBCSRV *next, *prev;
85 };
86
87 /*
88  * Keep directory entries in a list
89  */
90 struct smbc_dir_list {
91         struct smbc_dir_list *next;
92         struct smbc_dirent *dirent;
93 };
94
95
96 /*
97  * Structure for open file management
98  */
99 struct _SMBCFILE {
100         int cli_fd;
101         char *fname;
102         off_t offset;
103         struct _SMBCSRV *srv;
104         bool file;
105         struct smbc_dir_list *dir_list, *dir_end, *dir_next;
106         int dir_type, dir_error;
107
108         SMBCFILE *next, *prev;
109 };
110
111
112 /*
113  * Context structure
114  */
115 struct SMBC_internal_data {
116
117         /* True when this handle is initialized */
118         bool                                    initialized;
119
120         /* dirent pointer location */
121         struct smbc_dirent                      dirent;
122         /*
123          * Leave room for any urlencoded filename and the comment field.
124          *
125          * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
126          * plus a couple of null terminators (one after the filename,
127          * one after the comment).
128          *
129          * According to <linux/limits.h>, NAME_MAX is 255.  Is it longer
130          * anyplace else?
131          */
132         char                                    _dirent_name[1024];
133
134         /*
135          * server connection list
136          */
137         SMBCSRV *                               servers;
138
139         /*
140          * open file/dir list
141          */
142         SMBCFILE *                              files;
143
144         /*
145          * Support "Create Time" in get/set with the *xattr() functions, if
146          * true.  This replaces the dos attribute strings C_TIME, A_TIME and
147          * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
148          * CREATE_TIME.  Default is FALSE, i.e.  to use the old-style shorter
149          * names and to not support CREATE time, for backward compatibility.
150          */
151         bool                                    full_time_names;
152
153         /*
154          * The share mode of a file being opened.  To match POSIX semantics
155          * (and maintain backward compatibility), DENY_NONE is the default.
156          */
157         smbc_share_mode                         share_mode;
158
159         /*
160          * Authentication function which includes the context.  This will be
161          * used if set; otherwise context->callbacks.auth_fn() will be used.
162          */
163         smbc_get_auth_data_with_context_fn      auth_fn_with_context;
164
165         /*
166          * An opaque (to this library) user data handle which can be set
167          * and retrieved with smbc_option_set() and smbc_option_get().
168          */
169         void *                                  user_data;
170
171         /*
172          * Should we attempt UNIX smb encryption ?
173          * Set to 0 if we should never attempt, set to 1 if
174          * encryption requested, set to 2 if encryption required.
175          */
176         smbc_smb_encrypt_level                  smb_encryption_level;
177
178         /*
179          * Should we request case sensitivity of file names?
180          */
181         bool                                    case_sensitive;
182
183         /*
184          * Auth info needed for DFS traversal.
185          */
186
187         struct user_auth_info                   *auth_info;
188
189         struct smbc_server_cache * server_cache;
190
191         /* POSIX emulation functions */
192         struct
193         {
194 #if 0 /* Left in libsmbclient.h for backward compatibility */
195                 smbc_open_fn                    open_fn;
196                 smbc_creat_fn                   creat_fn;
197                 smbc_read_fn                    read_fn;
198                 smbc_write_fn                   write_fn;
199                 smbc_unlink_fn                  unlink_fn;
200                 smbc_rename_fn                  rename_fn;
201                 smbc_lseek_fn                   lseek_fn;
202                 smbc_stat_fn                    stat_fn;
203                 smbc_fstat_fn                   fstat_fn;
204 #endif
205                 smbc_statvfs_fn                 statvfs_fn;
206                 smbc_fstatvfs_fn                fstatvfs_fn;
207                 smbc_ftruncate_fn               ftruncate_fn;
208 #if 0 /* Left in libsmbclient.h for backward compatibility */
209                 smbc_close_fn                   close_fn;
210                 smbc_opendir_fn                 opendir_fn;
211                 smbc_closedir_fn                closedir_fn;
212                 smbc_readdir_fn                 readdir_fn;
213                 smbc_getdents_fn                getdents_fn;
214                 smbc_mkdir_fn                   mkdir_fn;
215                 smbc_rmdir_fn                   rmdir_fn;
216                 smbc_telldir_fn                 telldir_fn;
217                 smbc_lseekdir_fn                lseekdir_fn;
218                 smbc_fstatdir_fn                fstatdir_fn;
219                 smbc_chmod_fn                   chmod_fn;
220                 smbc_utimes_fn                  utimes_fn;
221                 smbc_setxattr_fn                setxattr_fn;
222                 smbc_getxattr_fn                getxattr_fn;
223                 smbc_removexattr_fn             removexattr_fn;
224                 smbc_listxattr_fn               listxattr_fn;
225 #endif
226         }               posix_emu;
227
228 #if 0 /* Left in libsmbclient.h for backward compatibility */
229         /* Printing-related functions */
230         struct
231         {
232                 smbc_print_file_fn              print_file_fn;
233                 smbc_open_print_job_fn          open_print_job_fn;
234                 smbc_list_print_jobs_fn         list_print_jobs_fn;
235                 smbc_unlink_print_job_fn        unlink_print_job_fn;
236         }               printing;
237 #endif
238
239 #if 0 /* None available yet */
240         /* SMB high-level functions */
241         struct
242         {
243         }               smb;
244
245 #endif
246         uint16_t        port;
247 };      
248
249 /* Functions in libsmb_cache.c */
250 int
251 SMBC_add_cached_server(SMBCCTX * context,
252                        SMBCSRV * newsrv,
253                        const char * server,
254                        const char * share,
255                        const char * workgroup,
256                        const char * username);
257
258 SMBCSRV *
259 SMBC_get_cached_server(SMBCCTX * context,
260                        const char * server,
261                        const char * share,
262                        const char * workgroup,
263                        const char * user);
264
265 int
266 SMBC_remove_cached_server(SMBCCTX * context,
267                           SMBCSRV * server);
268
269 int
270 SMBC_purge_cached_servers(SMBCCTX * context);
271
272
273 /* Functions in libsmb_dir.c */
274 int
275 SMBC_check_options(char *server,
276                    char *share,
277                    char *path,
278                    char *options);
279
280 SMBCFILE *
281 SMBC_opendir_ctx(SMBCCTX *context,
282                  const char *fname);
283
284 int
285 SMBC_closedir_ctx(SMBCCTX *context,
286                   SMBCFILE *dir);
287
288 struct smbc_dirent *
289 SMBC_readdir_ctx(SMBCCTX *context,
290                  SMBCFILE *dir);
291
292 int
293 SMBC_getdents_ctx(SMBCCTX *context,
294                   SMBCFILE *dir,
295                   struct smbc_dirent *dirp,
296                   int count);
297
298 int
299 SMBC_mkdir_ctx(SMBCCTX *context,
300                const char *fname,
301                mode_t mode);
302
303 int
304 SMBC_rmdir_ctx(SMBCCTX *context,
305                const char *fname);
306
307 off_t
308 SMBC_telldir_ctx(SMBCCTX *context,
309                  SMBCFILE *dir);
310
311 int
312 SMBC_lseekdir_ctx(SMBCCTX *context,
313                   SMBCFILE *dir,
314                   off_t offset);
315
316 int
317 SMBC_fstatdir_ctx(SMBCCTX *context,
318                   SMBCFILE *dir,
319                   struct stat *st);
320
321 int
322 SMBC_chmod_ctx(SMBCCTX *context,
323                const char *fname,
324                mode_t newmode);
325
326 int
327 SMBC_utimes_ctx(SMBCCTX *context,
328                 const char *fname,
329                 struct timeval *tbuf);
330
331 int
332 SMBC_unlink_ctx(SMBCCTX *context,
333                 const char *fname);
334
335 int
336 SMBC_rename_ctx(SMBCCTX *ocontext,
337                 const char *oname,
338                 SMBCCTX *ncontext,
339                 const char *nname);
340
341
342 /* Functions in libsmb_file.c */
343 SMBCFILE *
344 SMBC_open_ctx(SMBCCTX *context,
345               const char *fname,
346               int flags,
347               mode_t mode);
348
349 SMBCFILE *
350 SMBC_creat_ctx(SMBCCTX *context,
351                const char *path,
352                mode_t mode);
353
354 ssize_t
355 SMBC_read_ctx(SMBCCTX *context,
356               SMBCFILE *file,
357               void *buf,
358               size_t count);
359
360 ssize_t
361 SMBC_write_ctx(SMBCCTX *context,
362                SMBCFILE *file,
363                const void *buf,
364                size_t count);
365
366 int
367 SMBC_close_ctx(SMBCCTX *context,
368                SMBCFILE *file);
369
370 bool
371 SMBC_getatr(SMBCCTX * context,
372             SMBCSRV *srv,
373             const char *path,
374             uint16 *mode,
375             off_t *size,
376             struct timespec *create_time_ts,
377             struct timespec *access_time_ts,
378             struct timespec *write_time_ts,
379             struct timespec *change_time_ts,
380             SMB_INO_T *ino);
381
382 bool
383 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
384             time_t create_time,
385             time_t access_time,
386             time_t write_time,
387             time_t change_time,
388             uint16 mode);
389
390 off_t
391 SMBC_lseek_ctx(SMBCCTX *context,
392                SMBCFILE *file,
393                off_t offset,
394                int whence);
395
396 int
397 SMBC_ftruncate_ctx(SMBCCTX *context,
398                    SMBCFILE *file,
399                    off_t length);
400
401
402 /* Functions in libsmb_misc.c */
403 int
404 SMBC_dlist_contains(SMBCFILE * list, SMBCFILE *p);
405
406 int
407 SMBC_errno(SMBCCTX *context,
408            struct cli_state *c);
409
410
411 /* Functions in libsmb_path.c */
412 int
413 SMBC_parse_path(TALLOC_CTX *ctx,
414                 SMBCCTX *context,
415                 const char *fname,
416                 char **pp_workgroup,
417                 char **pp_server,
418                 uint16_t *p_port,
419                 char **pp_share,
420                 char **pp_path,
421                 char **pp_user,
422                 char **pp_password,
423                 char **pp_options);
424
425
426 /* Functions in libsmb_printjob.c */
427 SMBCFILE *
428 SMBC_open_print_job_ctx(SMBCCTX *context,
429                         const char *fname);
430
431 int
432 SMBC_print_file_ctx(SMBCCTX *c_file,
433                     const char *fname,
434                     SMBCCTX *c_print,
435                     const char *printq);
436
437 int
438 SMBC_list_print_jobs_ctx(SMBCCTX *context,
439                          const char *fname,
440                          smbc_list_print_job_fn fn);
441
442 int
443 SMBC_unlink_print_job_ctx(SMBCCTX *context,
444                           const char *fname,
445                           int id);
446
447
448 /* Functions in libsmb_server.c */
449 int
450 SMBC_check_server(SMBCCTX * context,
451                   SMBCSRV * server);
452
453 int
454 SMBC_remove_unused_server(SMBCCTX * context,
455                           SMBCSRV * srv);
456
457 void
458 SMBC_get_auth_data(const char *server, const char *share,
459                    char *workgroup_buf, int workgroup_buf_len,
460                    char *username_buf, int username_buf_len,
461                    char *password_buf, int password_buf_len);
462
463 SMBCSRV *
464 SMBC_find_server(TALLOC_CTX *ctx,
465                  SMBCCTX *context,
466                  const char *server,
467                  const char *share,
468                  char **pp_workgroup,
469                  char **pp_username,
470                  char **pp_password);
471
472 SMBCSRV *
473 SMBC_server(TALLOC_CTX *ctx,
474             SMBCCTX *context,
475             bool connect_if_not_found,
476             const char *server,
477             uint16_t port,
478             const char *share,
479             char **pp_workgroup,
480             char **pp_username,
481             char **pp_password);
482
483 SMBCSRV *
484 SMBC_attr_server(TALLOC_CTX *ctx,
485                  SMBCCTX *context,
486                  const char *server,
487                  uint16_t port,
488                  const char *share,
489                  char **pp_workgroup,
490                  char **pp_username,
491                  char **pp_password);
492
493
494 /* Functions in libsmb_stat.c */
495 int
496 SMBC_stat_ctx(SMBCCTX *context,
497               const char *fname,
498               struct stat *st);
499
500 int
501 SMBC_fstat_ctx(SMBCCTX *context,
502                SMBCFILE *file,
503                struct stat *st);
504
505
506 int
507 SMBC_statvfs_ctx(SMBCCTX *context,
508                  char *path,
509                  struct statvfs *st);
510
511
512 int
513 SMBC_fstatvfs_ctx(SMBCCTX *context,
514                   SMBCFILE *file,
515                   struct statvfs *st);
516
517
518 /* Functions in libsmb_xattr.c */
519 int
520 SMBC_setxattr_ctx(SMBCCTX *context,
521                   const char *fname,
522                   const char *name,
523                   const void *value,
524                   size_t size,
525                   int flags);
526
527 int
528 SMBC_getxattr_ctx(SMBCCTX *context,
529                   const char *fname,
530                   const char *name,
531                   const void *value,
532                   size_t size);
533
534 int
535 SMBC_removexattr_ctx(SMBCCTX *context,
536                      const char *fname,
537                      const char *name);
538
539 int
540 SMBC_listxattr_ctx(SMBCCTX *context,
541                    const char *fname,
542                    char *list,
543                    size_t size);
544
545
546 #endif