PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/mod_ftpd.h

https://github.com/OutOfOrder/mod_ftpd
C Header | 275 lines | 188 code | 42 blank | 45 comment | 0 complexity | 812ebef62ec193cac28d051fa601ab88 MD5 | raw file
  1. /* $id$ */
  2. /* Copyright 2003-2004 Edward Rudd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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. #ifndef _MOD_FTPD_H_
  17. #define _MOD_FTPD_H_
  18. #include "apr_hooks.h"
  19. #include "httpd.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Current version of the Plugin interface */
  24. #define FTPD_PLUGIN_VERSION 20050414
  25. /* Create a set of FTPD_DECLARE(type), FTPD_DECLARE_NONSTD(type) and
  26. * FTPD_DECLARE_DATA with appropriate export and import tags for the platform
  27. */
  28. #if !defined(WIN32)
  29. #define FTPD_DECLARE(type) type
  30. #define FTPD_DECLARE_NONSTD(type) type
  31. #define FTPD_DECLARE_DATA
  32. #elif defined(FTPD_DECLARE_STATIC)
  33. #define FTPD_DECLARE(type) type __stdcall
  34. #define FTPD_DECLARE_NONSTD(type) type
  35. #define FTPD_DECLARE_DATA
  36. #elif defined(FTPD_DECLARE_EXPORT)
  37. #define FTPD_DECLARE(type) __declspec(dllexport) type __stdcall
  38. #define FTPD_DECLARE_NONSTD(type) __declspec(dllexport) type
  39. #define FTPD_DECLARE_DATA __declspec(dllexport)
  40. #else
  41. #define FTPD_DECLARE(type) __declspec(dllimport) type __stdcall
  42. #define FTPD_DECLARE_NONSTD(type) __declspec(dllimport) type
  43. #define FTPD_DECLARE_DATA __declspec(dllimport)
  44. #endif
  45. /* mod_ftp published internal strcutures */
  46. /* FTP handlers registration */
  47. #define HANDLER_PROTOTYPE request_rec *r, char *buffer, void *data
  48. #define HANDLER_FUNC(name) ftpd_handler_##name
  49. #define HANDLER_DECLARE(name) FTPD_DECLARE(int) HANDLER_FUNC(name) (HANDLER_PROTOTYPE)
  50. typedef FTPD_DECLARE(int) ftpd_handler(HANDLER_PROTOTYPE);
  51. FTPD_DECLARE(void) ftpd_register_handler(char *key, ftpd_handler *func, int states,
  52. const char *help_text, void *data, apr_pool_t *p);
  53. FTPD_DECLARE(void) ap_ftpd_str_toupper(char *str);
  54. /* FTP Return codes: Shamelessly borrowed from vsftp/ftpcodes.h */
  55. #define FTP_C_DATACONN "150"
  56. #define FTP_C_CLNTOK "200"
  57. #define FTP_C_NOOPOK "200"
  58. #define FTP_C_TYPEOK "200"
  59. #define FTP_C_PORTOK "200"
  60. #define FTP_C_UMASKOK "200"
  61. #define FTP_C_CHMODOK "200"
  62. #define FTP_C_FEATOK "211"
  63. #define FTP_C_SIZEOK "213"
  64. #define FTP_C_MDTMOK "213"
  65. #define FTP_C_HELPOK "214"
  66. #define FTP_C_SYSTOK "215"
  67. #define FTP_C_GREET "220"
  68. #define FTP_C_GOODBYE "221"
  69. #define FTP_C_ABOR_NOCONN "225"
  70. #define FTP_C_TRANSFEROK "226"
  71. #define FTP_C_ABOROK "226"
  72. #define FTP_C_PASVOK "227"
  73. #define FTP_C_EPASVOK "229"
  74. #define FTP_C_LOGINOK "230"
  75. #define FTP_C_CWDOK "250"
  76. #define FTP_C_RMDIROK "250"
  77. #define FTP_C_DELEOK "250"
  78. #define FTP_C_RENAMEOK "250"
  79. #define FTP_C_PWDOK "257"
  80. #define FTP_C_MKDIROK "257"
  81. #define FTP_C_GIVEPWORD "331"
  82. #define FTP_C_RESTOK "350"
  83. #define FTP_C_RNFROK "350"
  84. #define FTP_C_IDLE_TIMEOUT "421"
  85. #define FTP_C_DATA_TIMEOUT "421"
  86. #define FTP_C_NOLOGIN "421"
  87. #define FTP_C_BADSENDCONN "425"
  88. #define FTP_C_BADSENDNET "426"
  89. #define FTP_C_BADSENDFILE "451"
  90. #define FTP_C_PASVFAIL "451"
  91. #define FTP_C_BADCMD "500"
  92. #define FTP_C_CMDNOTIMPL "502"
  93. #define FTP_C_CMDDISABLED "502"
  94. #define FTP_C_BADHELP "502"
  95. #define FTP_C_NEEDUSER "503"
  96. #define FTP_C_NEEDRNFR "503"
  97. #define FTP_C_INVALIDARG "504"
  98. #define FTP_C_INVALID_PROTO "522"
  99. #define FTP_C_LOGINERR "530"
  100. #define FTP_C_FILEFAIL "550"
  101. #define FTP_C_PERMDENY "550"
  102. #define FTP_C_UPLOADFAIL "553"
  103. #define FTP_C_RENAMEFAIL "553"
  104. /* FTP methods */
  105. enum {
  106. FTPD_M_CHDIR = 0,
  107. FTPD_M_LIST,
  108. /* FTPD_M_STOU,*/
  109. FTPD_M_APPEND,
  110. FTPD_M_XRMD,
  111. FTPD_M_LAST
  112. };
  113. /* Handler return codes */
  114. enum {
  115. FTPD_HANDLER_OK = 0, /* Everthings OK */
  116. FTPD_HANDLER_QUIT, /* Terminate the connection */
  117. FTPD_HANDLER_PERMDENY, /* Permision was denied */
  118. FTPD_HANDLER_FILENOTFOUND, /* File does not exist */
  119. FTPD_HANDLER_SERVERERROR, /* Other server error */
  120. FTPD_HANDLER_USER_UNKNOWN, /* User is unknown */
  121. FTPD_HANDLER_USER_NOT_ALLOWED, /* User not allowed to login */
  122. FTPD_HANDLER_UPDATE_AUTH, /* Update the global auth credentials */
  123. FTPD_HANDLER_UPDATE_AGENT, /* Update the global UserAgent */
  124. FTPD_HANDLER_LAST
  125. };
  126. /* Current Data Pipe state */
  127. typedef enum {
  128. FTPD_PIPE_NONE = 0,
  129. FTPD_PIPE_PASV,
  130. FTPD_PIPE_PORT,
  131. FTPD_PIPE_OPEN,
  132. FTPD_PIPE_LAST
  133. } ftpd_pipe_state;
  134. /* connection state and handler flags */
  135. typedef enum {
  136. FTPD_STATE_AUTH = 0x001, /* The initial connection state */
  137. FTPD_STATE_USER_ACK = 0x002, /* a username has been provided, password expected */
  138. FTPD_STATE_TRANS_NODATA = 0x004, /* standard transaction state */
  139. FTPD_STATE_TRANS_DATA = 0x008, /* a pasv or port or variant has been provided for file transfer */
  140. FTPD_STATE_RENAME = 0x010, /* a from name has been provided, a to name is expected */
  141. FTPD_FLAG_EPSV_LOCK = 0x020, /* Flag: which commands are locked in epsv all state */
  142. FTPD_FLAG_NOT_IMPLEMENTED = 0x040, /* Flag: an unimplimented command */
  143. FTPD_FLAG_FEATURE = 0x080, /* Flag: a Feature listed in FEAT */
  144. FTPD_FLAG_HIDE_ARGS = 0x100, /* Flag: hide arguments in logging */
  145. FTPD_FLAG_LOG_COMMAND = 0x200 /* Flag: log this command in the access log */
  146. } ftpd_state;
  147. /* All States connection states */
  148. #define FTPD_ALL_STATES FTPD_STATE_AUTH | FTPD_STATE_USER_ACK | FTPD_STATE_TRANS_NODATA \
  149. | FTPD_STATE_TRANS_DATA | FTPD_STATE_RENAME
  150. /* All command Flags */
  151. #define FTPD_ALL_FLAGS FTPD_FLAG_EPSV_LOCK | FTPD_FLAG_NOT_IMPLEMENTED | FTPD_FLAG_FEATURE \
  152. | FTPD_FLAG_HIDE_ARGS | FTPD_FLAG_LOG_COMMAND
  153. /* Transaction state is both DATA and NODATA */
  154. #define FTPD_STATE_TRANSACTION (FTPD_STATE_TRANS_NODATA | FTPD_STATE_TRANS_DATA)
  155. typedef struct ftpd_datacon_rec {
  156. apr_pool_t *p;
  157. ftpd_pipe_state type;
  158. union {
  159. apr_socket_t *pasv;
  160. apr_sockaddr_t *port;
  161. };
  162. apr_socket_t *pipe;
  163. } ftpd_datacon_rec;
  164. typedef struct ftpd_user_rec {
  165. apr_pool_t *p;
  166. conn_rec *c;
  167. server_rec *s;
  168. char *user;
  169. char *passwd;
  170. char *auth_string;
  171. const char *chroot;
  172. char *current_directory;
  173. char *useragent;
  174. apr_byte_t binaryflag;
  175. apr_off_t restart_position;
  176. char *rename_file;
  177. ftpd_datacon_rec data;
  178. ftpd_state state;
  179. apr_byte_t epsv_lock;
  180. } ftpd_user_rec;
  181. /* Gets a pointer to the internal session state structure */
  182. FTPD_DECLARE_NONSTD(ftpd_user_rec) *ftpd_get_user_rec(const request_rec *r);
  183. /*
  184. * FTP Plugins
  185. *
  186. */
  187. /*
  188. * ftpd_provider
  189. *
  190. * This structure defines all of the hooks that an FTP plugin can provide.
  191. *
  192. */
  193. #define FTPD_PROVIDER_GROUP "ftpd"
  194. /* chroot hooks */
  195. typedef enum {
  196. FTPD_CHROOT_USER_FOUND = 0, /* User is found and chroot has been set */
  197. FTPD_CHROOT_USER_NOT_FOUND, /* User not found pass to next provider */
  198. FTPD_CHROOT_FAIL /* Fail the login */
  199. } ftpd_chroot_status_t;
  200. /* limit hooks */
  201. typedef enum {
  202. FTPD_LIMIT_DEFAULT = 0, /* returned from checkin/checkout */
  203. FTPD_LIMIT_ALLOW, /* Another user is allowed to login */
  204. FTPD_LIMIT_TOOMANY /* Too many users logged in */
  205. } ftpd_limit_status_t;
  206. typedef enum {
  207. FTPD_LIMIT_CHECK = 0, /* Just check to see if a space is available */
  208. FTPD_LIMIT_CHECKIN, /* user is logging in so count them */
  209. FTPD_LIMIT_CHECKOUT /* user has left the server.. uncount them */
  210. } ftpd_limit_check_t;
  211. /* masin provider structure */
  212. typedef struct {
  213. /* Get the chroot directory for the specified user */
  214. ftpd_chroot_status_t (*map_chroot)(
  215. const request_rec *r,
  216. const char **chroot,
  217. const char **initroot
  218. );
  219. ftpd_limit_status_t (*limit_check)(
  220. const request_rec *r,
  221. ftpd_limit_check_t check_type
  222. );
  223. } ftpd_provider;
  224. typedef struct ftpd_provider_list ftpd_provider_list;
  225. struct ftpd_provider_list {
  226. const char *name;
  227. const ftpd_provider *provider;
  228. ftpd_provider_list *next;
  229. };
  230. #ifdef __cplusplus
  231. }
  232. #endif
  233. #endif /*_MOD_FTPD_H_*/