1
2
3
4
5
6 #ifndef MC__VFS_SFTPFS_INTERNAL_H
7 #define MC__VFS_SFTPFS_INTERNAL_H
8
9 #include <libssh2.h>
10 #include <libssh2_sftp.h>
11
12 #include "lib/vfs/vfs.h"
13 #include "lib/vfs/xdirentry.h"
14
15
16
17 #define SFTP_DEFAULT_PORT 22
18
19
20 #ifndef LIBSSH2_INVALID_SOCKET
21 #define LIBSSH2_INVALID_SOCKET -1
22 #endif
23
24 #define SFTP_SUPER(super) ((sftpfs_super_t *) (super))
25
26
27
28 typedef enum
29 {
30 NONE = 0,
31 PUBKEY = (1 << 0),
32 PASSWORD = (1 << 1),
33 AGENT = (1 << 2)
34 } sftpfs_auth_type_t;
35
36
37
38 typedef struct
39 {
40 struct vfs_s_super base;
41
42 sftpfs_auth_type_t auth_type;
43 sftpfs_auth_type_t config_auth_type;
44
45 LIBSSH2_KNOWNHOSTS *known_hosts;
46 char *known_hosts_file;
47
48 LIBSSH2_SESSION *session;
49 LIBSSH2_SFTP *sftp_session;
50
51 LIBSSH2_AGENT *agent;
52
53 char *pubkey;
54 char *privkey;
55
56 int socket_handle;
57 const char *ip_address;
58 vfs_path_element_t *original_connection_info;
59 } sftpfs_super_t;
60
61
62
63 extern GString *sftpfs_filename_buffer;
64 extern struct vfs_s_subclass sftpfs_subclass;
65 extern struct vfs_class *vfs_sftpfs_ops;
66
67
68
69 void sftpfs_init_config_variables_patterns (void);
70 void sftpfs_deinit_config_variables_patterns (void);
71
72 gboolean sftpfs_is_sftp_error (LIBSSH2_SFTP * sftp_session, int sftp_res, int sftp_error);
73 void sftpfs_ssherror_to_gliberror (sftpfs_super_t * super, int libssh_errno, GError ** mcerror);
74 gboolean sftpfs_waitsocket (sftpfs_super_t * super, int sftp_res, GError ** mcerror);
75
76 const GString *sftpfs_fix_filename (const char *file_name);
77 void sftpfs_attr_to_stat (const LIBSSH2_SFTP_ATTRIBUTES * attrs, struct stat *s);
78 int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);
79 int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);
80 int sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mcerror);
81 int sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror);
82 int sftpfs_utime (const vfs_path_t * vpath, time_t atime, time_t mtime, GError ** mcerror);
83 int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
84 int sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror);
85 int sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror);
86
87 void sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** mcerror);
88 int sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror);
89 void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message,
90 GError ** mcerror);
91
92 vfs_file_handler_t *sftpfs_fh_new (struct vfs_s_inode *ino, gboolean changed);
93
94 void *sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror);
95 struct vfs_dirent *sftpfs_readdir (void *data, GError ** mcerror);
96 int sftpfs_closedir (void *data, GError ** mcerror);
97 int sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
98 int sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror);
99
100 gboolean sftpfs_open_file (vfs_file_handler_t * fh, int flags, mode_t mode, GError ** mcerror);
101 ssize_t sftpfs_read_file (vfs_file_handler_t * fh, char *buffer, size_t count, GError ** mcerror);
102 ssize_t sftpfs_write_file (vfs_file_handler_t * fh, const char *buffer, size_t count,
103 GError ** mcerror);
104 int sftpfs_close_file (vfs_file_handler_t * fh, GError ** mcerror);
105 int sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror);
106 off_t sftpfs_lseek (vfs_file_handler_t * fh, off_t offset, int whence, GError ** mcerror);
107
108
109
110 #endif