"Fossies" - the Fresh Open Source Software Archive

Member "mod_ftp-0.9.6/include/mod_ftp.h" (29 Sep 2009, 12296 Bytes) of package /linux/www/apache_httpd_modules/old/mod_ftp-0.9.6-beta.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mod_ftp.h" see the Fossies "Dox" file reference documentation.

    1 /* Licensed to the Apache Software Foundation (ASF) under one or more
    2  * contributor license agreements.  See the NOTICE file distributed with
    3  * this work for additional information regarding copyright ownership.
    4  * The ASF licenses this file to You under the Apache License, Version 2.0
    5  * (the "License"); you may not use this file except in compliance with
    6  * the License.  You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 /*
   18  * Original Copyright (c) 2005 Covalent Technologies
   19  *
   20  * FTP Protocol module for Apache 2.0
   21  */
   22 
   23 #ifndef MOD_FTP_H
   24 #define MOD_FTP_H
   25 
   26 #include "apr_general.h" /* stringify */
   27 
   28 #define MODFTP_COPYRIGHT \
   29   "Copyright 2009 The Apache Software Foundation."
   30 
   31 #define MODFTP_VERSION_MAJOR  0
   32 #define MODFTP_VERSION_MINOR  9
   33 #define MODFTP_VERSION_SUBVER 6
   34 #define MODFTP_VERSION_DEV    0
   35 
   36 #if MODFTP_VERSION_DEV
   37 #define MODFTP_VERSION_DEVSTR "-dev"
   38 #else
   39 #define MODFTP_VERSION_DEVSTR ""
   40 #endif
   41 
   42 #define MODFTP_REVISION      APR_STRINGIFY(MODFTP_VERSION_MAJOR) \
   43                          "." APR_STRINGIFY(MODFTP_VERSION_MINOR) \
   44                          "." APR_STRINGIFY(MODFTP_VERSION_SUBVER)
   45 #define MODFTP_VERSION       MODFTP_REVISION MODFTP_VERSION_DEVSTR
   46 
   47 #define MODFTP_PRODUCT       "mod_ftp/" MODFTP_VERSION
   48 
   49 #ifndef VERSION_ONLY
   50 
   51 #include "httpd.h"
   52 #include "http_config.h"
   53 
   54 #ifdef __cplusplus
   55 extern "C" {
   56 #endif
   57 
   58 
   59 /* FTP Reply Codes */
   60 
   61 #define FTP_REPLY_RESTART_MARKER          110
   62 #define FTP_REPLY_SERVICE_READY_IN_N_MIN  120
   63 #define FTP_REPLY_DATA_ALREADY_OPEN       125
   64 #define FTP_REPLY_FILE_STATUS_OK          150
   65 #define FTP_REPLY_COMMAND_OK              200
   66 #define FTP_REPLY_NOT_IMPLEMENTED         202
   67 #define FTP_REPLY_SYSTEM_STATUS           211
   68 #define FTP_REPLY_DIRECTORY_STATUS        212
   69 #define FTP_REPLY_FILE_STATUS             213
   70 #define FTP_REPLY_HELP_MESSAGE            214
   71 #define FTP_REPLY_SYSTEM_TYPE             215
   72 #define FTP_REPLY_SERVICE_READY           220
   73 #define FTP_REPLY_CONTROL_CLOSE           221
   74 #define FTP_REPLY_DATA_OPEN               225
   75 #define FTP_REPLY_DATA_CLOSE              226
   76 #define FTP_REPLY_PASSIVE_MODE            227
   77 #define FTP_REPLY_EXTENDED_PASSIVE_MODE   229
   78 #define FTP_REPLY_USER_LOGGED_IN          230
   79 #define FTP_REPLY_USER_LOGGED_IN_SECURE   232
   80 #define FTP_REPLY_SECURITY_EXCHANGE_DONE  234
   81 #define FTP_REPLY_COMPLETED               250
   82 #define FTP_REPLY_PATH_CREATED            257
   83 #define FTP_REPLY_USER_OK                 331
   84 #define FTP_REPLY_NEED_ACCOUNT            332
   85 #define FTP_REPLY_PENDING                 350
   86 #define FTP_REPLY_SERVICE_NOT_AVAILABLE   421
   87 #define FTP_REPLY_CANNOT_OPEN_DATACONN    425
   88 #define FTP_REPLY_TRANSFER_ABORTED        426
   89 #define FTP_REPLY_FILE_BUSY               450
   90 #define FTP_REPLY_LOCAL_ERROR             451
   91 #define FTP_REPLY_INSUFFICIENT_SPACE      452
   92 #define FTP_REPLY_COMMAND_UNRECOGNIZED    500
   93 #define FTP_REPLY_SYNTAX_ERROR            501
   94 #define FTP_REPLY_COMMAND_NOT_IMPLEMENTED 502
   95 #define FTP_REPLY_BAD_SEQUENCE            503
   96 #define FTP_REPLY_COMMAND_NOT_IMPL_PARAM  504
   97 #define FTP_REPLY_BAD_PROTOCOL            522
   98 #define FTP_REPLY_NOT_LOGGED_IN           530
   99 #define FTP_REPLY_NEED_ACCOUNT_TO_STORE   532
  100 #define FTP_REPLY_PROT_NOT_SUPPORTED      536
  101 #define FTP_REPLY_FILE_NOT_FOUND          550
  102 #define FTP_REPLY_PAGE_TYPE_UNKNOWN       551
  103 #define FTP_REPLY_EXEEDED_STORAGE         552
  104 #define FTP_REPLY_FILENAME_NOT_ALLOWED    553
  105 #define FTP_REPLY_INVALID_REST_PARAM      554
  106 #define FTP_REPLY_TYPE_OR_STRU_MISMATCH   555
  107 
  108 #if defined(WIN32) && defined(FTP_DECLARE_EXPORT)
  109 #define FTP_DECLARE_DATA __declspec(dllexport)
  110 #define FTP_DECLARE(fn)  __declspec(dllexport) fn
  111 #elif defined(WIN32)
  112 #define FTP_DECLARE_DATA __declspec(dllimport)
  113 #define FTP_DECLARE(fn)  __declspec(dllimport) fn
  114 #else
  115 #define FTP_DECLARE_DATA 
  116 #define FTP_DECLARE(fn)  fn
  117 #endif
  118 
  119 /* Must be available to reach ftp configuration structures */
  120 extern module FTP_DECLARE_DATA ftp_module;
  121 
  122 /* The main ftp server configuration */
  123 typedef struct ftp_server_config
  124 {
  125     int enabled;
  126     int options;
  127     int implicit_ssl;
  128     int timeout_login;
  129     int timeout_idle;
  130     int timeout_data;
  131     int active_min;
  132     int active_max;
  133     int pasv_min;
  134     int pasv_max;
  135     char *pasv_addr;
  136     char *pasv_bindaddr;
  137     int pasv_bindfamily;
  138     int epsv_ignore_family;
  139     int data_block_size;
  140     const char *banner_message;
  141     int banner_message_isfile;
  142     const char *exit_message;
  143     int exit_message_isfile;
  144     const char *homedir;
  145     const char *docrootenv;
  146     int jailuser;
  147     int max_login_attempts;
  148     int limit_peruser;
  149     int limit_perip;
  150     int limit_perserver;
  151     const char *limitdbfile;
  152 } ftp_server_config;
  153 
  154 typedef struct ftp_dir_config
  155 {
  156     const char *readme;
  157     const char *path;
  158     int readme_isfile;
  159     apr_fileperms_t fileperms;
  160     apr_fileperms_t dirperms;
  161 } ftp_dir_config;
  162 
  163 #define ftp_get_module_config(v) \
  164     ap_get_module_config(v, &ftp_module)
  165 #define ftp_set_module_config(v,val) \
  166     ap_set_module_config(v, &ftp_module, val)
  167 
  168 /* 
  169  * FTP connection structure.  Each connection to the server will
  170  * have an ftp_connection structure associated with it.
  171  */
  172 typedef struct ftp_connection
  173 {
  174     conn_rec *connection;     /* The connection */
  175     server_rec *orig_server;  /* Stow the original server for reset */
  176     int close_connection;     /* Final control command was processed */
  177     const char *response_notes; /* Notes for response handling. */
  178 
  179     /* User information */
  180     apr_pool_t *login_pool;   /* Child of c->pool reset on every USER cmd */
  181     int logged_in;
  182     const char *host;
  183     const char *user;
  184     const char *authorization;
  185     int login_attempts;
  186 
  187     /* Security information */
  188     int auth;                 /* The AUTH type.  One of NONE/SSL/TLS */
  189     int pbsz;                 /* Data protection buffer size.  Usually zero. */
  190     int prot;                 /* Data channel protection level. C/S/E/P */
  191     int is_secure;
  192     void *ssl_input_ctx;
  193     void *ssl_output_ctx;
  194 
  195     /* Connection stats */
  196     int files;                /* STOR/RETR transfer count */
  197     apr_off_t bytes;          /* Only STOR/RETR style traffic */
  198     int transfers;            /* All data transfers including LIST/NLST */
  199     apr_off_t traffic;        /* Total data channel traffic, plus HELP */
  200 
  201     /* Command state */
  202     char *cwd;                /* APR_PATH_MAX+1 buffer for Current Directory */
  203     char *rename_from;        /* APR_PATH_MAX+1 buffer for the RNFR command */
  204     int type;                 /* FTP transmission (TYPE_A/TYPE_I) */
  205     apr_off_t restart_point;  /* For data transfers */
  206     int filter_mask;          /* Filters required (CRLF, BYTERANGE, etc) */
  207 
  208     /* Data channel state */
  209     apr_pool_t *data_pool;    /* Child of c->pool reset on every data cmd */
  210     int all_epsv;             /* EPSV ALL command issued (refuse all others) */
  211     apr_socket_t *csock;      /* The local data socket we connect/accept on */
  212     apr_socket_t *datasock;   /* The remote data socket we send/recv on */
  213     apr_sockaddr_t *clientsa; /* The remote sa of this data connection */
  214     apr_time_t passive_created; /* Passive creation time or (-1) for active */
  215 
  216     /* Look-ahead for "next" command */
  217     apr_socket_t *cntlsock;   /* The control socket to watch for next cmd */
  218     apr_pool_t *next_pool;    /* Storage to get us to the next request_rec */
  219     apr_bucket_brigade *next_bb; /* Holding brigade for request look-ahead */
  220     char *next_request;       /* The next control command */
  221     apr_size_t next_reqsize;  /* Size of the next control command */
  222 } ftp_connection;
  223 
  224 /*
  225  * This is the generic registration function, 
  226  * see ftp_hook_cmd or ftp_hook_cmd_alias.
  227  */
  228 typedef int ftp_hook_fn(request_rec *r, const char *arg);
  229 
  230 FTP_DECLARE(void) ftp_hook_cmd_any(const char *key, ftp_hook_fn *pf, 
  231                                    const char *alias, int order, 
  232                                    int flags, const char *help);
  233 
  234 /* Flags for each FTP command handler.
  235  *
  236  * FTP_TAKE0 - This command takes no arguments.
  237  * FTP_TAKE1 - This command takes a single argument.
  238  * FTP_KEEP_WHITESPACE  - leading and trailing spaces are significant.
  239  * FTP_NEED_LOGIN - The user needs to be logged in to execute this command.
  240  * FTP_DATA_INTR - The current data transfer is interrupted by this command.
  241  * FTP_NEW_FEAT - This command was introduced following RFC 2389, show in FEAT list.
  242  *                Also see comments for ftp_feat_advert() below.
  243  * FTP_NO_HELP - Implicit if the command key contains a space, this flag omits 
  244  *               a given FTP command from the HELP listing.
  245  * FTP_EXTENSIBLE - Upon all cmd handlers declining, reply is COMMAND_NOT_IMPL_PARAM
  246  *                  rather than COMMAND_NOT_IMPLEMENTED
  247  * FTP_TAKE1_PATH - This command takes a single argument, delimited by a single
  248  *                  space, with leading and trailing spaces significant.
  249  */
  250 #define FTP_TAKE0            (1 << 0)
  251 #define FTP_TAKE1            (1 << 1)
  252 #define FTP_NEED_LOGIN       (1 << 5)
  253 #define FTP_DATA_INTR        (1 << 6)
  254 #define FTP_NEW_FEAT         (1 << 7)
  255 #define FTP_NO_HELP          (1 << 8)
  256 #define FTP_EXTENSIBLE       (1 << 9)
  257 #define FTP_KEEP_WHITESPACE  (1 << 10)
  258 
  259 #define FTP_TAKE1_PATH       (FTP_TAKE1 | FTP_KEEP_WHITESPACE)
  260 
  261 /* FTP command handler ordering */
  262 #define FTP_HOOK_FIRST  10
  263 #define FTP_HOOK_MIDDLE 20
  264 #define FTP_HOOK_LAST   30
  265 
  266 /*
  267  * This this the main hook that is used to hook into mod_ftp.  The
  268  * key is the command, i.e. "DELE".  The ftp_hook_fn is the function 
  269  * pointer that will handle this request.  The flags variable is an 
  270  * integer that is used to tell the dispatcher (ftp_run_cmd) properties
  271  * about the handler that is about to be run.  These flags include 
  272  * whether the user needs to be logged in, and how many arguments we 
  273  * expect the command to have. See the flags above for details.  The 
  274  * final argument is the help string that will be displayed if the user
  275  * does "HELP cmd".
  276  */
  277 #define ftp_hook_cmd(aliascmd, pf, order, flags, desc) \
  278     ftp_hook_cmd_any((aliascmd), (pf), NULL, (order), \
  279                      (flags), (desc))
  280 
  281 /*
  282  * This this the alternate hook that is used to hook command aliases
  283  * into mod_ftp.  The key is the aliased command, i.e. "XPWD".  
  284  * The ftp_hook_fn is used instead to store the base command, i.e. "PWD".
  285  * The flags variable is an integer that is used to tell the dispatcher 
  286  * (ftp_run_cmd) properties about the handler that is about to be run.  
  287  * These flags must match the base command hook registration.  This macro
  288  * will always add FTP_ALIAS_CMD to the flags.  See the flags above for 
  289  * details of other flags.  The final argument is the help string that will 
  290  * be displayed if the user does "HELP cmd".
  291  */
  292 #define ftp_hook_cmd_alias(aliascmd, basecmd, order, flags, desc) \
  293     ftp_hook_cmd_any((aliascmd), NULL, (basecmd), (order), \
  294                      (flags) , (desc))
  295 
  296 /*
  297  * This this for registration of a non-command based feature which should
  298  * be reported by the FEAT query, but not the HELP query.  An example is
  299  * "REST STREAM", where the HELP command and hook is registered for REST,
  300  * but the FEAT advertised is "REST STREAM".
  301  */
  302 #define ftp_feat_advert(feature) \
  303     ftp_hook_cmd_any((feature), NULL, NULL, FTP_HOOK_LAST, \
  304                      FTP_NEW_FEAT | FTP_NO_HELP, "")
  305 
  306 /*
  307  * This command escapes text (not containing end of line) to protect the
  308  * the special characters CR and 0xFF, by trailing CR with IAC NOP (which
  309  * is effectively NULL) and 0xFF with a second 0xFF, for transmission over
  310  * the control connection as part of a single-line response.
  311  *
  312  * Note that the resulting string may be the origin string if transformation
  313  * is not required.
  314  */
  315 FTP_DECLARE(const char *) ftp_escape_control_text(const char *s,
  316                                                   apr_pool_t *pool);
  317 
  318 #ifdef __cplusplus
  319 }
  320 #endif
  321 
  322 #endif
  323 
  324 #endif
  325