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