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