s3: smbd: Reformat users of can_write_to_file().
[samba.git] / source3 / smbd / proto.h
index 7829546c987eb6cba8772459b7ccec66665dae03..5303c477cf7b16ad5aaf35a4213ce019b41e7f17 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);
@@ -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,13 @@ 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);
+                       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,9 +352,6 @@ 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);
 
 /* The following definitions come from smbd/filename.c  */
@@ -349,6 +368,10 @@ NTSTATUS check_name(connection_struct *conn,
 int get_real_filename(connection_struct *conn, const char *path,
                      const char *name, 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,
@@ -368,11 +391,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);
@@ -412,6 +434,16 @@ 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_at(connection_struct *conn,
+                                  struct files_struct *dirfsp,
+                                  const struct smb_filename *smb_dname,
+                                  struct files_struct **_fsp);
+
+NTSTATUS open_internal_dirfsp_at(connection_struct *conn,
+                                struct files_struct *dirfsp,
+                                const struct smb_filename *smb_dname,
+                                struct files_struct **_fsp);
+
 /* The following definitions come from smbd/ipc.c  */
 
 NTSTATUS nt_status_np_pipe(NTSTATUS status);
@@ -469,10 +501,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,
@@ -488,9 +526,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,
@@ -665,9 +712,10 @@ 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,
@@ -709,8 +757,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);
@@ -740,15 +787,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);
 
@@ -786,7 +830,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,
@@ -795,9 +839,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,
@@ -864,6 +905,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);
@@ -983,6 +1025,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,
@@ -990,6 +1033,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,
@@ -1060,6 +1104,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);
@@ -1069,7 +1114,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,
@@ -1182,6 +1226,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,7 +1247,7 @@ NTSTATUS check_user_share_access(connection_struct *conn,
                                uint32_t *p_share_access,
                                bool *p_readonly_share);
 bool change_to_user_and_service(connection_struct *conn, uint64_t vuid);
-bool change_to_user_by_fsp(struct files_struct *fsp);
+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);
@@ -1198,11 +1255,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);
@@ -1230,6 +1287,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);
@@ -1246,13 +1304,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 */