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