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