1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
/*
* This file is part of the Green End SFTP Server.
* Copyright (C) 2007, 2011 Richard Kettlewell
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
/** @file sftpserver.h @brief SFTP server parameters and common declarations */
#ifndef SFTPSERVER_H
#define SFTPSERVER_H
#include "sftpcommon.h"
#include <sys/types.h>
#ifndef MAXNAMES
/** @brief Maximum size of an @ref SSH_FXP_READDIR response */
# define MAXNAMES 32
#endif
#ifndef MAXHANDLES
/** @brief Maximum number of concurrent handles */
# define MAXHANDLES 128
#endif
#ifndef MAXREAD
/** @brief Maximum read size */
# define MAXREAD 1048576
#endif
#ifndef MAXREQUEST
/** @brief Maximum request size */
# define MAXREQUEST 1048576
#endif
#ifndef DEFAULT_PERMISSIONS
/** @brief Default file permissions */
# define DEFAULT_PERMISSIONS 0755
#endif
#ifndef NTHREADS
/** @brief Number of threads */
# define NTHREADS 4
#endif
/** @brief Send an @ref SSH_FXP_STATUS message
* @param job Job
* @param status Status code
* @param msg Human-readable message
*/
void sftp_send_status(struct sftpjob *job,
uint32_t status,
const char *msg);
/** @brief @ref SSH_FXP_INIT stub for use after initialization
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_already_init(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_REMOVE implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_remove(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_RMDIR implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_rmdir(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_SYMLINK implementation
* @param job Job
* @return Error code
*
* This for protocols 4 and above.
*/
uint32_t sftp_v345_symlink(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_READLINK implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_readlink(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_CLOSE implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_close(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_READ implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_read(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_WRITE implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_write(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_SETSTAT implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_setstat(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_FSETSTAT implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_fsetstat(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_OPENDIR implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_opendir(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_READDIR implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_readdir(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_MKDIR implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_mkdir(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_EXTENDED implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_extended(struct sftpjob *job);
/** @brief Send a filename list as found in an @ref SSH_FXP_NAME response
* @param job Job
* @param nnames Number of names
* @param names Filenames (and attributes) to send
* @return Error code
*
* This is for protocols 4 and above.
*/
void sftp_v456_sendnames(struct sftpjob *job,
int nnames, const struct sftpattr *names);
/** @brief Send file attributes
* @param job Job
* @param attrs File attributes
* @return Error code
*
* This is for protocols 4 and above.
*/
void sftp_v456_sendattrs(struct sftpjob *job,
const struct sftpattr *attrs);
/** @brief Parse file attributes
* @param job Job
* @param attrs Where to put file attributes
* @return Error code
*
* This is for protocols 4 and above.
*/
uint32_t sftp_v456_parseattrs(struct sftpjob *job, struct sftpattr *attrs);
/** @brief Encode a filename for transmission
* @param job Job
* @param path Input/output filename
* @return 0 on success, -1 on error (as per sftp_iconv())
*
* This is for protocol 3 only; @c *path is not modified.
*/
int sftp_v3_encode(struct sftpjob *job, char **path);
/** @brief Encode a filename for transmission
* @param job Job
* @param path Input/output filename
* @return 0 on success, -1 on error (as per sftp_iconv())
*
* This is for protocols 4 and above; @c *path is replaced with the UTF-8
* version of the filename.
*/
int sftp_v456_encode(struct sftpjob *job, char **path);
/** @brief Decode a filename
* @param job Job
* @param path Input/output filename
* @return Error code
*
* This is for protocols 4 and above; @c *path is translated from UTF-8 to the
* current multibyte encoding.
*/
uint32_t sftp_v456_decode(struct sftpjob *job, char **path);
/** @brief Generic @ref SSH_FXP_RENAME implementation
* @param job Job
* @return Error code
*
* This is for protocols 3 and 4.
*/
uint32_t sftp_v34_rename(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_OPEN implementation
* @param job Job
* @return Error code
*
* This is for protocols 3 and 4.
*/
uint32_t sftp_v34_open(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_LSTAT implementation
* @param job Job
* @return Error code
*
* This is for protocols 4 and above.
*/
uint32_t sftp_v456_lstat(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_STAT implementation
* @param job Job
* @return Error code
*
* This is for protocols 4 and above.
*/
uint32_t sftp_v456_stat(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_FSTAT implementation
* @param job Job
* @return Error code
*
* This is for protocols 4 and above.
*/
uint32_t sftp_v456_fstat(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_REALPATH implementation
* @param job Job
* @return Error code
*
* This is for protocols 3-5.
*/
uint32_t sftp_v345_realpath(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_OPEN implementation
* @param job Job
* @return Error code
*
* This is for protocols 5 and above.
*/
uint32_t sftp_v56_open(struct sftpjob *job);
/** @brief Generic @ref SSH_FXP_RENAME implementation
* @param job Job
* @return Error code
*
* This is for protocols 5 and above.
*/
uint32_t sftp_v56_rename(struct sftpjob *job);
/** @brief @ref SSH_FXP_REALPATH implementation
* @param job Job
* @return Error code
*
* This is for protocol 6 only.
*/
uint32_t sftp_v6_realpath(struct sftpjob *job);
/** @brief @ref SSH_FXP_LINK implementation
* @param job Job
* @return Error code
*
* This is for protocol 6 only.
*/
uint32_t sftp_v6_link(struct sftpjob *job);
/** @brief @c text-seek extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_text_seek(struct sftpjob *job);
/** @brief Common code for @ref SSH_FXP_OPEN
* @param job Job
* @param path Path to open (should already have been translated)
* @param desired_access Access required (TODO link to valid bits)
* @param flags Open flags (TODO link to valid bits)
* @param attrs Initial attributes for new files
* @return Error code
*/
uint32_t sftp_generic_open(struct sftpjob *job, const char *path,
uint32_t desired_access, uint32_t flags,
struct sftpattr *attrs);
/** @brief @c space-available extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_space_available(struct sftpjob *job);
/** @brief @c version-select extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_v6_version_select(struct sftpjob *job);
/** @brief @c fsync@openssh.com extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_fsync(struct sftpjob *job);
/** @brief @c hardlink@openssh.com extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_hardlink(struct sftpjob *job);
/** @brief @c posix-rename@openssh.org extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_posix_rename(struct sftpjob *job);
/** @brief @c statfs@openssh.org extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_statfs(struct sftpjob *job);
/** @brief @c fstatvfs@openssh.com extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_fstatvfs(struct sftpjob *job);
/** @brief @c statvfs@openssh.com extension implementation
* @param job Job
* @return Error code
*/
uint32_t sftp_vany_statvfs(struct sftpjob *job);
/** @brief Send an @ref SSH_FXP_STATUS message based on @c errno
* @param job Job
*/
void sftp_send_errno_status(struct sftpjob *job);
#endif /* SFTPSERVER_H */
/*
Local Variables:
c-basic-offset:2
comment-column:40
fill-column:79
indent-tabs-mode:nil
End:
*/
|