smbd: add dirfsp arg to SMB_VFS_CREATE_FILE()
[amitay/samba.git] / source3 / smbd / proto.h
index ef24cf0578d455674fe5800f1d1a3021431ab745..c2491f9c43b0c5b2ce016d3935b14db12cbd1f5c 100644 (file)
@@ -49,6 +49,7 @@
 /* The following definitions come from smbd/signing.c  */
 
 struct smbXsrv_connection;
+struct dcesrv_context;
 
 bool srv_check_sign_mac(struct smbXsrv_connection *conn,
                        const char *inbuf, uint32_t *seqnum, bool trusted_channel);
@@ -108,7 +109,7 @@ struct tevent_req *smbd_smb1_do_locks_send(
        struct tevent_context *ev,
        struct smb_request **smbreq, /* talloc_move()d into our state */
        struct files_struct *fsp,
-       uint32_t timeout,
+       uint32_t lock_timeout,
        bool large_offset,
        enum brl_flavour lock_flav,
        uint16_t num_locks,
@@ -154,12 +155,22 @@ connection_struct *conn_new(struct smbd_server_connection *sconn);
 bool conn_idle_all(struct smbd_server_connection *sconn, time_t t);
 void conn_clear_vuid_caches(struct smbd_server_connection *sconn, uint64_t vuid);
 void conn_free(connection_struct *conn);
-void conn_force_tdis(struct smbd_server_connection *sconn, const char *sharename);
+void conn_force_tdis(
+       struct smbd_server_connection *sconn,
+       bool (*check_fn)(struct connection_struct *conn,
+                        void *private_data),
+       void *private_data);
 void msg_force_tdis(struct messaging_context *msg,
                    void *private_data,
                    uint32_t msg_type,
                    struct server_id server_id,
                    DATA_BLOB *data);
+void msg_force_tdis_denied(
+       struct messaging_context *msg,
+       void *private_data,
+       uint32_t msg_type,
+       struct server_id server_id,
+       DATA_BLOB *data);
 
 /* The following definitions come from smbd/connection.c  */
 
@@ -213,7 +224,12 @@ bool get_dir_entry(TALLOC_CTX *ctx,
                struct timespec *date,
                bool check_descend,
                bool ask_sharemode);
-bool is_visible_file(connection_struct *conn, const char *dir_path, const char *name, SMB_STRUCT_STAT *pst, bool use_veto);
+struct smb_Dir;
+bool is_visible_file(connection_struct *conn,
+               struct smb_Dir *dir_hnd,
+               const char *name,
+               SMB_STRUCT_STAT *pst,
+               bool use_veto);
 struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx,
                        connection_struct *conn,
                        const struct smb_filename *smb_fname,
@@ -248,7 +264,7 @@ bool smbd_setup_mdns_registration(struct tevent_context *ev,
 
 mode_t unix_mode(connection_struct *conn, int dosmode,
                 const struct smb_filename *smb_fname,
-                const char *inherit_from_dir);
+                struct smb_filename *smb_fname_parent);
 uint32_t dos_mode_msdfs(connection_struct *conn,
                      const struct smb_filename *smb_fname);
 uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname);
@@ -257,8 +273,11 @@ struct tevent_req *dos_mode_at_send(TALLOC_CTX *mem_ctx,
                                    files_struct *dir_fsp,
                                    struct smb_filename *smb_fname);
 NTSTATUS dos_mode_at_recv(struct tevent_req *req, uint32_t *dosmode);
-int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
-                    uint32_t dosmode, const char *parent_dir, bool newfile);
+int file_set_dosmode(connection_struct *conn,
+                    struct smb_filename *smb_fname,
+                    uint32_t dosmode,
+                    struct smb_filename *parent_dir,
+                    bool newfile);
 NTSTATUS file_set_sparse(connection_struct *conn,
                         struct files_struct *fsp,
                         bool sparse);
@@ -312,10 +331,14 @@ void reply_openerror(struct smb_request *req, NTSTATUS status);
 /* The following definitions come from smbd/file_access.c  */
 
 bool can_delete_file_in_directory(connection_struct *conn,
-                                 const struct smb_filename *smb_fname);
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname);
 bool can_write_to_file(connection_struct *conn,
-                      const struct smb_filename *smb_fname);
-bool directory_has_default_acl(connection_struct *conn, const char *fname);
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname);
+bool directory_has_default_acl(connection_struct *conn,
+                       struct files_struct *dirfsp,
+                       struct smb_filename *smb_fname);
 NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32_t dosmode);
 
 /* The following definitions come from smbd/fileio.c  */
@@ -330,11 +353,7 @@ ssize_t write_file(struct smb_request *req,
                        const char *data,
                        off_t pos,
                        size_t n);
-void delete_write_cache(files_struct *fsp);
-void set_filelen_write_cache(files_struct *fsp, off_t file_size);
-ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason);
 NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_through);
-int fsp_stat(files_struct *fsp);
 
 /* The following definitions come from smbd/filename.c  */
 
@@ -343,18 +362,34 @@ uint32_t filename_create_ucf_flags(struct smb_request *req, uint32_t create_disp
 NTSTATUS unix_convert(TALLOC_CTX *ctx,
                      connection_struct *conn,
                      const char *orig_path,
+                     NTTIME twrp,
                      struct smb_filename **smb_fname,
                      uint32_t ucf_flags);
 NTSTATUS check_name(connection_struct *conn,
                        const struct smb_filename *smb_fname);
-int get_real_filename(connection_struct *conn, const char *path,
-                     const char *name, TALLOC_CTX *mem_ctx,
+NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname,
+                                   uint32_t ucf_flags,
+                                   NTTIME twrp);
+int get_real_filename(connection_struct *conn,
+                     struct smb_filename *path,
+                     const char *name,
+                     TALLOC_CTX *mem_ctx,
                      char **found_name);
+int get_real_filename_full_scan(connection_struct *conn,
+                               const char *path,
+                               const char *name,
+                               bool mangled,
+                               TALLOC_CTX *mem_ctx,
+                               char **found_name);
+char *get_original_lcomp(TALLOC_CTX *ctx,
+                       connection_struct *conn,
+                       const char *filename_in,
+                       uint32_t ucf_flags);
 NTSTATUS filename_convert(TALLOC_CTX *mem_ctx,
                        connection_struct *conn,
                        const char *name_in,
                        uint32_t ucf_flags,
-                       time_t *twrp,
+                       NTTIME twrp,
                        bool *ppath_contains_wcard,
                        struct smb_filename **pp_smb_fname);
 NTSTATUS filename_convert_with_privilege(TALLOC_CTX *mem_ctx,
@@ -369,11 +404,10 @@ NTSTATUS filename_convert_with_privilege(TALLOC_CTX *mem_ctx,
 
 NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
                 files_struct **result);
+void fsp_set_gen_id(files_struct *fsp);
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result);
 void file_close_conn(connection_struct *conn);
-void file_close_pid(struct smbd_server_connection *sconn, uint16_t smbpid,
-                   uint64_t vuid);
 bool file_init_global(void);
 bool file_init(struct smbd_server_connection *sconn);
 void file_close_user(struct smbd_server_connection *sconn, uint64_t vuid);
@@ -413,6 +447,15 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                           const struct smb_filename *smb_fname_in);
 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen);
 
+NTSTATUS create_internal_dirfsp(connection_struct *conn,
+                               const struct smb_filename *smb_dname,
+                               struct files_struct **_fsp);
+
+NTSTATUS open_internal_dirfsp(connection_struct *conn,
+                             const struct smb_filename *smb_dname,
+                             int open_flags,
+                             struct files_struct **_fsp);
+
 /* The following definitions come from smbd/ipc.c  */
 
 NTSTATUS nt_status_np_pipe(NTSTATUS status);
@@ -470,10 +513,16 @@ void reply_sendend(struct smb_request *req);
 
 /* The following definitions come from smbd/msdfs.c  */
 
+bool parse_msdfs_symlink(TALLOC_CTX *ctx,
+                       bool shuffle_referrals,
+                       const char *target,
+                       struct referral **preflist,
+                       size_t *refcount);
 bool is_msdfs_link(connection_struct *conn,
                struct smb_filename *smb_fname);
 struct junction_map;
 NTSTATUS get_referred_path(TALLOC_CTX *ctx,
+                          struct auth_session_info *session_info,
                           const char *dfs_path,
                           const struct tsocket_address *remote_address,
                           const struct tsocket_address *local_address,
@@ -489,9 +538,18 @@ bool create_junction(TALLOC_CTX *ctx,
                const char *dfs_path,
                bool allow_broken_path,
                struct junction_map *jucn);
-bool create_msdfs_link(const struct junction_map *jucn);
-bool remove_msdfs_link(const struct junction_map *jucn);
-struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx, size_t *p_num_jn);
+struct referral;
+char *msdfs_link_string(TALLOC_CTX *ctx,
+               const struct referral *reflist,
+               size_t referral_count);
+bool create_msdfs_link(const struct junction_map *jucn,
+                      struct auth_session_info *session_info);
+bool remove_msdfs_link(const struct junction_map *jucn,
+                      struct auth_session_info *session_info);
+
+struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx,
+                                     struct auth_session_info *session_info,
+                                     size_t *p_num_jn);
 NTSTATUS resolve_dfspath_wcard(TALLOC_CTX *ctx,
                                connection_struct *conn,
                                const char *name_in,
@@ -656,19 +714,22 @@ void reply_nttranss(struct smb_request *req);
 /* The following definitions come from smbd/open.c  */
 
 NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
+                               struct files_struct *dirfsp,
                                const struct smb_filename *smb_fname,
                                bool use_privs,
                                uint32_t access_mask);
 NTSTATUS check_parent_access(struct connection_struct *conn,
+                               struct files_struct *dirfsp,
                                struct smb_filename *smb_fname,
                                uint32_t access_mask);
 NTSTATUS fd_open(struct connection_struct *conn, files_struct *fsp,
                 int flags, mode_t mode);
 NTSTATUS fd_close(files_struct *fsp);
 void change_file_owner_to_parent(connection_struct *conn,
-                                const char *inherit_from_dir,
+                                struct smb_filename *inherit_from_dir,
                                 files_struct *fsp);
-bool is_stat_open(uint32_t access_mask);
+bool is_oplock_stat_open(uint32_t access_mask);
+bool is_lease_stat_open(uint32_t access_mask);
 NTSTATUS send_break_message(struct messaging_context *msg_ctx,
                            const struct file_id *id,
                            const struct share_mode_entry *exclusive,
@@ -690,7 +751,7 @@ struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp,
                                 uint16_t lease_epoch);
 NTSTATUS create_file_default(connection_struct *conn,
                             struct smb_request *req,
-                            uint16_t root_dir_fid,
+                            struct files_struct **dirfsp,
                             struct smb_filename * smb_fname,
                             uint32_t access_mask,
                             uint32_t share_access,
@@ -710,8 +771,7 @@ NTSTATUS create_file_default(connection_struct *conn,
 
 /* The following definitions come from smbd/oplock.c  */
 
-uint32_t get_lease_type(const struct share_mode_data *d,
-                       const struct share_mode_entry *e);
+uint32_t get_lease_type(const struct share_mode_entry *e, struct file_id id);
 
 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);
 NTSTATUS set_file_oplock(files_struct *fsp);
@@ -741,15 +801,12 @@ void init_kernel_oplocks(struct smbd_server_connection *sconn);
 
 /* The following definitions come from smbd/oplock_linux.c  */
 
-void linux_set_lease_capability(void);
 int linux_set_lease_sighandler(int fd);
 int linux_setlease(int fd, int leasetype);
 struct kernel_oplocks *linux_init_kernel_oplocks(struct smbd_server_connection *sconn);
 
 /* The following definitions come from smbd/password.c  */
 
-struct user_struct *get_valid_user_struct(struct smbd_server_connection *sconn,
-                                         uint64_t vuid);
 void invalidate_vuid(struct smbd_server_connection *sconn, uint64_t vuid);
 int register_homes_share(const char *username);
 
@@ -787,7 +844,7 @@ int get_acl_group_bits( connection_struct *conn,
                        const struct smb_filename *smb_fname,
                        mode_t *mode);
 int inherit_access_posix_acl(connection_struct *conn,
-                       const char *inherit_from_dir,
+                       struct smb_filename *inherit_from_dir,
                        const struct smb_filename *smb_fname,
                        mode_t mode);
 NTSTATUS set_unix_posix_default_acl(connection_struct *conn,
@@ -796,9 +853,6 @@ NTSTATUS set_unix_posix_default_acl(connection_struct *conn,
 NTSTATUS set_unix_posix_acl(connection_struct *conn, files_struct *fsp,
                                uint16_t num_acls,
                                const char *pdata);
-NTSTATUS get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname,
-                            uint32_t security_info_wanted,
-                            struct security_descriptor **sd);
 int posix_sys_acl_blob_get_file(vfs_handle_struct *handle,
                                const struct smb_filename *smb_fname,
                                TALLOC_CTX *mem_ctx,
@@ -865,6 +919,7 @@ bool smb1_parse_chain(TALLOC_CTX *mem_ctx, const uint8_t *buf,
 bool req_is_in_chain(const struct smb_request *req);
 void smbd_process(struct tevent_context *ev_ctx,
                  struct messaging_context *msg_ctx,
+                 struct dcesrv_context *dce_ctx,
                  int sock_fd,
                  bool interactive);
 bool fork_echo_handler(struct smbXsrv_connection *xconn);
@@ -984,6 +1039,7 @@ void reply_rmdir(struct smb_request *req);
 NTSTATUS rename_internals_fsp(connection_struct *conn,
                        files_struct *fsp,
                        const struct smb_filename *smb_fname_dst_in,
+                       const char *dst_original_lcomp,
                        uint32_t attrs,
                        bool replace_if_exists);
 NTSTATUS rename_internals(TALLOC_CTX *ctx,
@@ -991,6 +1047,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                        struct smb_request *req,
                        struct smb_filename *smb_fname_src,
                        struct smb_filename *smb_fname_dst,
+                       const char *dst_original_lcomp,
                        uint32_t attrs,
                        bool replace_if_exists,
                        bool src_has_wild,
@@ -1061,6 +1118,7 @@ void smbd_exit_server_cleanly(const char *const reason) _NORETURN_;
 /* The following definitions come from smbd/service.c  */
 
 bool set_conn_connectpath(connection_struct *conn, const char *connectpath);
+bool canonicalize_connect_path(connection_struct *conn);
 NTSTATUS set_conn_force_user_group(connection_struct *conn, int snum);
 void set_current_case_sensitive(connection_struct *conn, uint16_t flags);
 bool chdir_current_service(connection_struct *conn);
@@ -1070,7 +1128,6 @@ int find_service(TALLOC_CTX *ctx, const char *service, char **p_service_out);
 connection_struct *make_connection_smb2(struct smbd_smb2_request *req,
                                        struct smbXsrv_tcon *tcon,
                                        int snum,
-                                       struct user_struct *vuser,
                                        const char *pdev,
                                        NTSTATUS *pstatus);
 connection_struct *make_connection(struct smb_request *req,
@@ -1117,13 +1174,15 @@ ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
 /* The following definitions come from smbd/statcache.c  */
 
 void stat_cache_add( const char *full_orig_name,
-               char *translated_path,
+               const char *translated_path,
+               NTTIME twrp,
                bool case_sensitive);
 bool stat_cache_lookup(connection_struct *conn,
                        bool posix_paths,
                        char **pp_name,
                        char **pp_dirpath,
                        char **pp_start,
+                       NTTIME twrp,
                        SMB_STRUCT_STAT *pst);
 void smbd_send_stat_cache_delete_message(struct messaging_context *msg_ctx,
                                    const char *name);
@@ -1183,6 +1242,19 @@ void reply_findnclose(struct smb_request *req);
 void reply_trans2(struct smb_request *req);
 void reply_transs2(struct smb_request *req);
 
+enum perm_type {
+       PERM_NEW_FILE,
+       PERM_NEW_DIR,
+       PERM_EXISTING_FILE,
+       PERM_EXISTING_DIR
+};
+
+NTSTATUS unix_perms_from_wire(connection_struct *conn,
+                             const SMB_STRUCT_STAT *psbuf,
+                             uint32_t perms,
+                             enum perm_type ptype,
+                             mode_t *ret_perms);
+
 /* The following definitions come from smbd/uid.c  */
 
 bool change_to_guest(void);
@@ -1190,8 +1262,8 @@ NTSTATUS check_user_share_access(connection_struct *conn,
                                const struct auth_session_info *session_info,
                                uint32_t *p_share_access,
                                bool *p_readonly_share);
-bool change_to_user(connection_struct *conn, uint64_t vuid);
-bool change_to_user_by_fsp(struct files_struct *fsp);
+bool change_to_user_and_service(connection_struct *conn, uint64_t vuid);
+bool change_to_user_and_service_by_fsp(struct files_struct *fsp);
 bool smbd_change_to_root_user(void);
 bool smbd_become_authenticated_pipe_user(struct auth_session_info *session_info);
 bool smbd_unbecome_authenticated_pipe_user(void);
@@ -1199,11 +1271,11 @@ void become_root(void);
 void unbecome_root(void);
 void smbd_become_root(void);
 void smbd_unbecome_root(void);
-bool become_user(connection_struct *conn, uint64_t vuid);
-bool become_user_by_fsp(struct files_struct *fsp);
-bool become_user_by_session(connection_struct *conn,
+bool become_user_without_service(connection_struct *conn, uint64_t vuid);
+bool become_user_without_service_by_fsp(struct files_struct *fsp);
+bool become_user_without_service_by_session(connection_struct *conn,
                            const struct auth_session_info *session_info);
-bool unbecome_user(void);
+bool unbecome_user_without_service(void);
 uid_t get_current_uid(connection_struct *conn);
 gid_t get_current_gid(connection_struct *conn);
 const struct security_unix_token *get_current_utok(connection_struct *conn);
@@ -1222,6 +1294,8 @@ void sys_utmp_yield(const char *username, const char *hostname,
 bool vfs_init_custom(connection_struct *conn, const char *vfs_object);
 bool smbd_vfs_init(connection_struct *conn);
 NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname);
+bool vfs_valid_pread_range(off_t offset, size_t length);
+bool vfs_valid_pwrite_range(off_t offset, size_t length);
 ssize_t vfs_pwrite_data(struct smb_request *req,
                        files_struct *fsp,
                        const char *buffer,
@@ -1231,6 +1305,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len);
 int vfs_set_filelen(files_struct *fsp, off_t len);
 int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len);
 int vfs_fill_sparse(files_struct *fsp, off_t len);
+int vfs_set_blocking(files_struct *fsp, bool set);
 off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n);
 const char *vfs_readdirname(connection_struct *conn, void *p,
                            SMB_STRUCT_STAT *sbuf, char **talloced);
@@ -1247,13 +1322,13 @@ int vfs_stat_smb_basename(struct connection_struct *conn,
                        const struct smb_filename *smb_fname_in,
                        SMB_STRUCT_STAT *psbuf);
 NTSTATUS vfs_stat_fsp(files_struct *fsp);
-NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid);
 NTSTATUS vfs_streaminfo(connection_struct *conn,
                        struct files_struct *fsp,
                        const struct smb_filename *smb_fname,
                        TALLOC_CTX *mem_ctx,
                        unsigned int *num_streams,
                        struct stream_struct **streams);
+void init_smb_file_time(struct smb_file_time *ft);
 
 /* The following definitions come from smbd/avahi_register.c */