libsmb: Implement smbc_notify
[samba.git] / source3 / include / libsmb_internal.h
index 555b6ac138bffe5ae5b0e1b7cb955c2c0e986294..0e0045e8c0eb4d8d9f7efbf21f83eac1c63a3cba 100644 (file)
@@ -1,23 +1,23 @@
-/* 
+/*
    Unix SMB/Netbios implementation.
    SMB client library implementation
    Copyright (C) Andrew Tridgell 1998
    Copyright (C) Richard Sharpe 2000, 2002
    Copyright (C) John Terpstra 2000
-   Copyright (C) Tom Jansen (Ninja ISD) 2002 
+   Copyright (C) Tom Jansen (Ninja ISD) 2002
    Copyright (C) Derrell Lipman 2003-2008
    Copyright (C) Jeremy Allison 2007, 2008
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -29,6 +29,7 @@
 #define _LIBSMB_INTERNAL_H_
 
 #include "../include/libsmbclient.h"
+#include "libsmb/clirap.h"
 
 #define SMBC_MAX_NAME  1023
 #define SMBC_FILE_MODE (S_IFREG | 0444)
@@ -39,7 +40,7 @@
  */
 typedef struct DOS_ATTR_DESC {
        int mode;
-       SMB_OFF_T size;
+       off_t size;
        time_t create_time;
        time_t access_time;
        time_t write_time;
@@ -47,6 +48,10 @@ typedef struct DOS_ATTR_DESC {
        SMB_INO_T inode;
 } DOS_ATTR_DESC;
 
+/*
+ * Extension of libsmbclient.h's #defines
+ */
+#define SMB_CTX_FLAG_USE_NT_HASH (1 << 4)
 
 /*
  * Internal flags for extended attributes
@@ -73,15 +78,16 @@ struct _SMBCSRV {
        dev_t dev;
        bool no_pathinfo;
        bool no_pathinfo2;
+       bool no_pathinfo3;
         bool no_nt_session;
-        POLICY_HND pol;
+        struct policy_handle pol;
+       time_t last_echo_time;
 
        SMBCSRV *next, *prev;
-       
 };
 
-/* 
- * Keep directory entries in a list 
+/*
+ * Keep directory entries in a list
  */
 struct smbc_dir_list {
        struct smbc_dir_list *next;
@@ -91,11 +97,16 @@ struct smbc_dir_list {
 
 /*
  * Structure for open file management
- */ 
+ */
 struct _SMBCFILE {
-       int cli_fd; 
+       int cli_fd;
+       /*
+        * cache of cli_state we opened cli_fd on.
+        * Due to DFS can be a subsidiary connection to srv->cli
+        */
+       struct cli_state *targetcli;
        char *fname;
-       SMB_OFF_T offset;
+       off_t offset;
        struct _SMBCSRV *srv;
        bool file;
        struct smbc_dir_list *dir_list, *dir_end, *dir_next;
@@ -111,52 +122,31 @@ struct _SMBCFILE {
 struct SMBC_internal_data {
 
        /* True when this handle is initialized */
-       bool            initialized;
-
-#if 0 /* Left in libsmbclient.h for backward compatibility */
-        /* Netbios name used for making connections */
-        char *          netbios_name;
+       bool                                    initialized;
 
-        /* Workgroup used for making connections */
-        char *          workgroup;
-
-        /* Username used for making connections */
-        char *          user;
-
-        /* Debug level */
-        int             debug;
-
-        /* Connection timeout value */
-        int             timeout;
-#endif
-
-        /* dirent pointer location
-         *
+        /* dirent pointer location */
+       struct smbc_dirent                      dirent;
+       /*
          * Leave room for any urlencoded filename and the comment field.
          *
-         * We really should use sizeof(struct smbc_dirent) plus (NAME_MAX * 3)
-         * plus whatever the max length of a comment is, plus a couple of null
-         * terminators (one after the filename, one after the comment).
+        * We use (NAME_MAX * 3) plus whatever the max length of a comment is,
+        * plus a couple of null terminators (one after the filename,
+        * one after the comment).
          *
          * According to <linux/limits.h>, NAME_MAX is 255.  Is it longer
          * anyplace else?
          */
-       char            dirent[1024];
+       char                                    _dirent_name[1024];
 
        /*
          * server connection list
         */
-       SMBCSRV *       servers;
-       
+       SMBCSRV *                               servers;
+
        /*
          * open file/dir list
         */
-       SMBCFILE *      files;
-
-        /*
-         * Log to standard error instead of the more typical standard output
-         */
-        bool            debug_stderr;
+       SMBCFILE *                              files;
 
         /*
          * Support "Create Time" in get/set with the *xattr() functions, if
@@ -165,109 +155,45 @@ struct SMBC_internal_data {
          * CREATE_TIME.  Default is FALSE, i.e.  to use the old-style shorter
          * names and to not support CREATE time, for backward compatibility.
          */
-        bool            full_time_names;
+        bool                                    full_time_names;
 
         /*
          * The share mode of a file being opened.  To match POSIX semantics
          * (and maintain backward compatibility), DENY_NONE is the default.
          */
-        smbc_share_mode share_mode;
+        smbc_share_mode                         share_mode;
+
+        /*
+         * Authentication function which includes the context.  This will be
+         * used if set; otherwise context->callbacks.auth_fn() will be used.
+         */
+        smbc_get_auth_data_with_context_fn      auth_fn_with_context;
 
         /*
          * An opaque (to this library) user data handle which can be set
          * and retrieved with smbc_option_set() and smbc_option_get().
          */
-        void *          user_data;
+        void *                                  user_data;
 
         /*
-         * Should we attempt UNIX smb encryption ? 
+         * Should we attempt UNIX smb encryption ?
          * Set to 0 if we should never attempt, set to 1 if
          * encryption requested, set to 2 if encryption required.
          */
-        int             smb_encryption_level;
-
-        /*
-         * From how many local master browsers should the list of
-         * workgroups be retrieved?  It can take up to 12 minutes or
-         * longer after a server becomes a local master browser, for
-         * it to have the entire browse list (the list of
-         * workgroups/domains) from an entire network.  Since a client
-         * never knows which local master browser will be found first,
-         * the one which is found first and used to retrieve a browse
-         * list may have an incomplete or empty browse list.  By
-         * requesting the browse list from multiple local master
-         * browsers, a more complete list can be generated.  For small
-         * networks (few workgroups), it is recommended that this
-         * value be set to 0, causing the browse lists from all found
-         * local master browsers to be retrieved and merged.  For
-         * networks with many workgroups, a suitable value for this
-         * variable is probably somewhere around 3. (Default: 3).
-         */
-        int             browse_max_lmb_count;
-
-        /*
-         * There is a difference in the desired return strings from
-         * smbc_readdir() depending upon whether the filenames are to
-         * be displayed to the user, or whether they are to be
-         * appended to the path name passed to smbc_opendir() to call
-         * a further smbc_ function (e.g. open the file with
-         * smbc_open()).  In the former case, the filename should be
-         * in "human readable" form.  In the latter case, the smbc_
-         * functions expect a URL which must be url-encoded.  Those
-         * functions decode the URL.  If, for example, smbc_readdir()
-         * returned a file name of "abc%20def.txt", passing a path
-         * with this file name attached to smbc_open() would cause
-         * smbc_open to attempt to open the file "abc def.txt" since
-         * the %20 is decoded into a space.
-         *
-         * Set this option to True if the names returned by
-         * smbc_readdir() should be url-encoded such that they can be
-         * passed back to another smbc_ call.  Set it to False if the
-         * names returned by smbc_readdir() are to be presented to the
-         * user.
-         *
-         * For backwards compatibility, this option defaults to False.
-         */
-        bool            urlencode_readdir_entries;
+        smbc_smb_encrypt_level                  smb_encryption_level;
 
         /*
-         * Some Windows versions appear to have a limit to the number
-         * of concurrent SESSIONs and/or TREE CONNECTions.  In
-         * one-shot programs (i.e. the program runs and then quickly
-         * ends, thereby shutting down all connections), it is
-         * probably reasonable to establish a new connection for each
-         * share.  In long-running applications, the limitation can be
-         * avoided by using only a single connection to each server,
-         * and issuing a new TREE CONNECT when the share is accessed.
+         * Should we request case sensitivity of file names?
          */
-        bool            one_share_per_server;
-
-#if 0 /* Left in libsmbclient.h (flags) for backward compatibility */
-        /* Kerberos-related flags */
-        bool            use_kerberos;
-        bool            fallback_after_kerberos;
+        bool                                    case_sensitive;
 
-        /* Don't try to do automatic anonymous login */
-        bool            no_auto_anonymous_login;
+       /*
+        * Auth info needed for DFS traversal.
+        */
 
-        /* Server-related functions */
-        struct
-        {
-                smbc_get_auth_data_fn           get_auth_data_fn;
-                smbc_check_server_fn            check_server_fn;
-                smbc_remove_unused_server_fn    remove_unused_server_fn;
-        }               server;
+       struct user_auth_info                   *auth_info;
 
-        /* Cache-related functions */
-        struct
-        {
-                struct smbc_server_cache *      server_cache_data;
-                smbc_add_cached_srv_fn          add_cached_server_fn;
-                smbc_get_cached_srv_fn          get_cached_server_fn;
-                smbc_remove_cached_srv_fn       remove_cached_server_fn;
-                smbc_purge_cached_srv_fn        purge_cached_server_fn;
-        }               cache;
-#endif
+        struct smbc_server_cache * server_cache;
 
         /* POSIX emulation functions */
         struct
@@ -283,6 +209,8 @@ struct SMBC_internal_data {
                 smbc_stat_fn                    stat_fn;
                 smbc_fstat_fn                   fstat_fn;
 #endif
+                smbc_statvfs_fn                 statvfs_fn;
+                smbc_fstatvfs_fn                fstatvfs_fn;
                 smbc_ftruncate_fn               ftruncate_fn;
 #if 0 /* Left in libsmbclient.h for backward compatibility */
                 smbc_close_fn                   close_fn;
@@ -315,13 +243,14 @@ struct SMBC_internal_data {
         }               printing;
 #endif
 
-#if 0 /* None available yet */
         /* SMB high-level functions */
         struct
         {
+                smbc_splice_fn                  splice_fn;
+               smbc_notify_fn                  notify_fn;
         }               smb;
 
-#endif
+       uint16_t        port;
 };     
 
 /* Functions in libsmb_cache.c */
@@ -329,13 +258,13 @@ int
 SMBC_add_cached_server(SMBCCTX * context,
                        SMBCSRV * newsrv,
                        const char * server,
-                       const char * share, 
+                       const char * share,
                        const char * workgroup,
                        const char * username);
 
 SMBCSRV *
 SMBC_get_cached_server(SMBCCTX * context,
-                       const char * server, 
+                       const char * server,
                        const char * share,
                        const char * workgroup,
                        const char * user);
@@ -412,10 +341,16 @@ SMBC_unlink_ctx(SMBCCTX *context,
 
 int
 SMBC_rename_ctx(SMBCCTX *ocontext,
-                const char *oname, 
+                const char *oname,
                 SMBCCTX *ncontext,
                 const char *nname);
 
+int
+SMBC_notify_ctx(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive,
+               uint32_t completion_filter, unsigned callback_timeout_ms,
+               smbc_notify_callback_fn cb, void *private_data);
+
+
 
 /* Functions in libsmb_file.c */
 SMBCFILE *
@@ -438,9 +373,17 @@ SMBC_read_ctx(SMBCCTX *context,
 ssize_t
 SMBC_write_ctx(SMBCCTX *context,
                SMBCFILE *file,
-               void *buf,
+               const void *buf,
                size_t count);
 
+off_t
+SMBC_splice_ctx(SMBCCTX *context,
+                SMBCFILE *srcfile,
+                SMBCFILE *dstfile,
+                off_t count,
+                int (*splice_cb)(off_t n, void *priv),
+                void *priv);
+
 int
 SMBC_close_ctx(SMBCCTX *context,
                SMBCFILE *file);
@@ -448,9 +391,9 @@ SMBC_close_ctx(SMBCCTX *context,
 bool
 SMBC_getatr(SMBCCTX * context,
             SMBCSRV *srv,
-            char *path,
-            uint16 *mode,
-            SMB_OFF_T *size,
+            const char *path,
+            uint16_t *mode,
+            off_t *size,
             struct timespec *create_time_ts,
             struct timespec *access_time_ts,
             struct timespec *write_time_ts,
@@ -458,12 +401,12 @@ SMBC_getatr(SMBCCTX * context,
             SMB_INO_T *ino);
 
 bool
-SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, 
+SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
             time_t create_time,
             time_t access_time,
             time_t write_time,
             time_t change_time,
-            uint16 mode);
+            uint16_t mode);
 
 off_t
 SMBC_lseek_ctx(SMBCCTX *context,
@@ -487,22 +430,13 @@ SMBC_errno(SMBCCTX *context,
 
 
 /* Functions in libsmb_path.c */
-int
-SMBC_urldecode(char *dest,
-               char *src,
-               size_t max_dest_len);
-
-int
-SMBC_urlencode(char *dest,
-               char *src,
-               int max_dest_len);
-
 int
 SMBC_parse_path(TALLOC_CTX *ctx,
                SMBCCTX *context,
                 const char *fname,
                 char **pp_workgroup,
                 char **pp_server,
+                uint16_t *p_port,
                 char **pp_share,
                 char **pp_path,
                char **pp_user,
@@ -541,15 +475,6 @@ int
 SMBC_remove_unused_server(SMBCCTX * context,
                           SMBCSRV * srv);
 
-void
-SMBC_call_auth_fn(TALLOC_CTX *ctx,
-                  SMBCCTX *context,
-                  const char *server,
-                  const char *share,
-                  char **pp_workgroup,
-                  char **pp_username,
-                  char **pp_password);
-
 void
 SMBC_get_auth_data(const char *server, const char *share,
                    char *workgroup_buf, int workgroup_buf_len,
@@ -570,6 +495,7 @@ SMBC_server(TALLOC_CTX *ctx,
             SMBCCTX *context,
             bool connect_if_not_found,
             const char *server,
+            uint16_t port,
             const char *share,
             char **pp_workgroup,
             char **pp_username,
@@ -579,6 +505,7 @@ SMBCSRV *
 SMBC_attr_server(TALLOC_CTX *ctx,
                  SMBCCTX *context,
                  const char *server,
+                 uint16_t port,
                  const char *share,
                  char **pp_workgroup,
                  char **pp_username,
@@ -597,6 +524,18 @@ SMBC_fstat_ctx(SMBCCTX *context,
                struct stat *st);
 
 
+int
+SMBC_statvfs_ctx(SMBCCTX *context,
+                 char *path,
+                 struct statvfs *st);
+
+
+int
+SMBC_fstatvfs_ctx(SMBCCTX *context,
+                  SMBCFILE *file,
+                  struct statvfs *st);
+
+
 /* Functions in libsmb_xattr.c */
 int
 SMBC_setxattr_ctx(SMBCCTX *context,