1 /* 2 * wzdftpd - a modular and cool ftp server 3 * Copyright (C) 2002-2004 Pierre Chifflier 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * As a special exemption, Pierre Chifflier 20 * and other respective copyright holders give permission to link this program 21 * with OpenSSL, and distribute the resulting executable, without including 22 * the source code for OpenSSL in the source distribution. 23 */ 24 25 #ifndef __WZD_COMMANDS__ 26 #define __WZD_COMMANDS__ 27 28 #include "wzd_string.h" 29 30 typedef int (*wzd_function_command_t)(wzd_string_t *name, wzd_string_t *param, wzd_context_t *context); 31 32 typedef struct { 33 char *name; 34 unsigned int id; 35 36 wzd_function_command_t command; 37 wzd_function_command_t help_function; 38 39 wzd_string_t * external_command; 40 41 struct wzd_command_perm_t * perms; 42 } wzd_command_t; 43 44 /** \brief Initialize storage for server commands 45 * 46 * \param[out] _ctable Pointer to the allocated hash table 47 * 48 * \return 0 if ok 49 */ 50 int commands_init(CHTBL ** _ctable); 51 52 /** \brief Destroy stored commands, and free memory used for commands 53 * 54 * \param[in] _ctable Hash table containing commands 55 */ 56 void commands_fini(CHTBL * _ctable); 57 58 /** \brief Add a new FTP command, linked to a C function 59 * 60 * \param[in] _ctable Hash table containing commands 61 * \param[in] name The FTP command (for ex, XCRC). For a site command, append command 62 * name with a space: SITE_HELP 63 * \param[in] command The function which will be executed when receiving the FTP command 64 * \param[in] help A pointer to a help function (not used at the moment) 65 * \param[in] id A unique identifier (32 bits unsigned integer) for the command (see \ref wzd_token_t) 66 * 67 * \note Command names are case insensitive, and must be valid ASCII 68 */ 69 int commands_add(CHTBL * _ctable, 70 const char *name, 71 wzd_function_command_t command, 72 wzd_function_command_t help, 73 u32_t id); 74 75 /** \brief Add a new FTP command, linked to an external program (for ex, a perl module) 76 * 77 * \param[in] _ctable Hash table containing commands 78 * \param[in] name The FTP command (for ex, XCRC). For a site command, append command 79 * name with a space: SITE_HELP 80 * \param[in] external_command The application which will be executed when receiving the FTP command. 81 * The application can use protocols (see \ref hook_add_protocol) 82 * 83 * \note Command names are case insensitive, and must be valid ASCII 84 */ 85 int commands_add_external(CHTBL * _ctable, 86 const char *name, 87 const wzd_string_t *external_command); 88 89 /** \brief Add default FTP commands to hash table 90 * 91 * \param[in] _ctable Hash table containing commands 92 * 93 * \return 0 if ok 94 */ 95 int commands_add_defaults(CHTBL * _ctable); 96 97 /** \brief Search for command in registered commands 98 * 99 * \param[in] _ctable Hash table containing commands 100 * \param[in] str Command name to find 101 * 102 * \return 103 * - a wzd_command_t structure if the command has been found 104 * - NULL if not found 105 */ 106 wzd_command_t * commands_find(CHTBL * _ctable, wzd_string_t *str); 107 108 /** \brief Set permissions associated to a command 109 * 110 * Replace permissions for the specified command. 111 * The command must exist. 112 * 113 * \param[in] _ctable Hash table containing commands 114 * \param[in] permname The permission name 115 * \param[in] permline A string describing permissions 116 * \return 0 if command is ok 117 */ 118 int commands_set_permission(CHTBL * _ctable, const char * permname, const char * permline); 119 120 /** \brief Add permissions to a command 121 * 122 * Add permissions for the specified command. 123 * The command must exist. 124 * 125 * \param[in] _ctable Hash table containing commands 126 * \param[in] permname The permission name 127 * \param[in] permline A string describing permissions, to be appended 128 * \return 0 if command is ok 129 */ 130 int commands_add_permission(CHTBL * _ctable, const char * permname, const char * permline); 131 132 /** \brief Check if user is authorized to run specified command 133 * 134 * Check if the user in the specific context is allowed to run the command. 135 * 136 * \param[in] _ctable Hash table containing commands 137 * \param[in] context The client context 138 * \return 0 if ok 139 */ 140 int commands_check_permission(wzd_command_t * command, wzd_context_t * context); 141 142 /** \brief Delete permissions associated to a command 143 * 144 * Delete permissions associated to the command. 145 * 146 * \param[in] _ctable Hash table containing commands 147 * \param[in] str The command name 148 * \return 0 if ok 149 */ 150 int commands_delete_permission(CHTBL * _ctable, wzd_string_t * str); 151 152 #endif /* __WZD_COMMANDS__ */ 153 154