xref: /netbsd-src/crypto/external/bsd/openssh/dist/sftp-client.h (revision 9fb66d812c00ebfb445c0b47dea128f32aa6fe96)
1 /*	$NetBSD: sftp-client.h,v 1.12 2021/03/05 17:47:16 christos Exp $	*/
2 /* $OpenBSD: sftp-client.h,v 1.29 2020/12/04 02:41:10 djm Exp $ */
3 
4 /*
5  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Client side of SSH2 filexfer protocol */
21 
22 #ifndef _SFTP_CLIENT_H
23 #define _SFTP_CLIENT_H
24 
25 typedef struct SFTP_DIRENT SFTP_DIRENT;
26 
27 struct SFTP_DIRENT {
28 	char *filename;
29 	char *longname;
30 	Attrib a;
31 };
32 
33 /*
34  * Used for statvfs responses on the wire from the server, because the
35  * server's native format may be larger than the client's.
36  */
37 struct sftp_statvfs {
38 	u_int64_t f_bsize;
39 	u_int64_t f_frsize;
40 	u_int64_t f_blocks;
41 	u_int64_t f_bfree;
42 	u_int64_t f_bavail;
43 	u_int64_t f_files;
44 	u_int64_t f_ffree;
45 	u_int64_t f_favail;
46 	u_int64_t f_fsid;
47 	u_int64_t f_flag;
48 	u_int64_t f_namemax;
49 };
50 
51 /*
52  * Initialise a SSH filexfer connection. Returns NULL on error or
53  * a pointer to a initialized sftp_conn struct on success.
54  */
55 struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
56 
57 u_int sftp_proto_version(struct sftp_conn *);
58 
59 /* Close file referred to by 'handle' */
60 int do_close(struct sftp_conn *, const u_char *, u_int);
61 
62 /* Read contents of 'path' to NULL-terminated array 'dir' */
63 int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
64 
65 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
66 void free_sftp_dirents(SFTP_DIRENT **);
67 
68 /* Delete file 'path' */
69 int do_rm(struct sftp_conn *, const char *);
70 
71 /* Create directory 'path' */
72 int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
73 
74 /* Remove directory 'path' */
75 int do_rmdir(struct sftp_conn *, const char *);
76 
77 /* Get file attributes of 'path' (follows symlinks) */
78 Attrib *do_stat(struct sftp_conn *, const char *, int);
79 
80 /* Get file attributes of 'path' (does not follow symlinks) */
81 Attrib *do_lstat(struct sftp_conn *, const char *, int);
82 
83 /* Set file attributes of 'path' */
84 int do_setstat(struct sftp_conn *, const char *, Attrib *);
85 
86 /* Set file attributes of open file 'handle' */
87 int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
88 
89 /* Set file attributes of 'path', not following symlinks */
90 int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
91 
92 /* Canonicalise 'path' - caller must free result */
93 char *do_realpath(struct sftp_conn *, const char *);
94 
95 /* Get statistics for filesystem hosting file at "path" */
96 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
97 
98 /* Rename 'oldpath' to 'newpath' */
99 int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
100 
101 /* Link 'oldpath' to 'newpath' */
102 int do_hardlink(struct sftp_conn *, const char *, const char *);
103 
104 /* Rename 'oldpath' to 'newpath' */
105 int do_symlink(struct sftp_conn *, const char *, const char *);
106 
107 /* Call fsync() on open file 'handle' */
108 int do_fsync(struct sftp_conn *conn, u_char *, u_int);
109 
110 /*
111  * Download 'remote_path' to 'local_path'. Preserve permissions and times
112  * if 'pflag' is set
113  */
114 int do_download(struct sftp_conn *, const char *, const char *,
115     Attrib *, int, int, int);
116 
117 /*
118  * Recursively download 'remote_directory' to 'local_directory'. Preserve
119  * times if 'pflag' is set
120  */
121 int download_dir(struct sftp_conn *, const char *, const char *,
122     Attrib *, int, int, int, int);
123 
124 /*
125  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
126  * if 'pflag' is set
127  */
128 int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
129 
130 /*
131  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
132  * times if 'pflag' is set
133  */
134 int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
135     int);
136 
137 /* Concatenate paths, taking care of slashes. Caller must free result. */
138 char *path_append(const char *, const char *);
139 
140 /* Make absolute path if relative path and CWD is given. Does not modify
141  * original if the the path is already absolute. */
142 char *make_absolute(char *, const char *);
143 
144 /* Check if remote path is directory */
145 int remote_is_dir(struct sftp_conn *conn, const char *path);
146 
147 /* Check if local path is directory */
148 int local_is_dir(const char *path);
149 
150 /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
151 int globpath_is_dir(const char *pathname);
152 
153 #endif
154