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