1 /* 2 * ProFTPD - FTP server daemon 3 * Copyright (c) 1997, 1998 Public Flood Software 4 * Copyright (c) 1999, 2000 MacGyver aka Habeeb J. Dihu <macgyver@tos.net> 5 * Copyright (c) 2001-2017 The ProFTPD Project team 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 20 * 21 * As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu 22 * and other respective copyright holders give permission to link this program 23 * with OpenSSL, and distribute the resulting executable, without including 24 * the source code for OpenSSL in the source distribution. 25 */ 26 27 /* Server, command and associated prototypes. */ 28 29 #ifndef PR_DIRTREE_H 30 #define PR_DIRTREE_H 31 32 #include "pool.h" 33 #include "sets.h" 34 #include "table.h" 35 #include "configdb.h" 36 #include "netaddr.h" 37 38 struct conn_struc; 39 40 struct tcp_keepalive { 41 int keepalive_enabled; 42 int keepalive_idle; 43 int keepalive_count; 44 int keepalive_intvl; 45 }; 46 47 typedef struct server_struc { 48 struct server_struc *next, *prev; 49 50 struct pool_rec *pool; /* Memory pool for this server */ 51 xaset_t *set; /* Set holding all servers */ 52 53 /* The label/name for this server configuration. */ 54 const char *ServerName; 55 56 /* The address for this server configuration. */ 57 const char *ServerAddress; 58 59 /* The fully qualified domain name for this server configuration. */ 60 const char *ServerFQDN; 61 62 /* Port number to which to listen. A value of zero disables the server_rec. 63 */ 64 unsigned int ServerPort; 65 66 /* TCP settings: keepalive, max segment size, receive/send buffer sizes. 67 */ 68 69 struct tcp_keepalive *tcp_keepalive; 70 71 int tcp_mss_len; 72 73 /* If the tcp_rcvbuf_override/tcp_sndbuf_override flags are true, then 74 * the corresponding buffer lengths are to be configured as socket options 75 * via setsockopt(2). 76 */ 77 int tcp_rcvbuf_len; 78 unsigned char tcp_rcvbuf_override; 79 80 int tcp_sndbuf_len; 81 unsigned char tcp_sndbuf_override; 82 83 /* Administrator name */ 84 const char *ServerAdmin; 85 86 /* Internal address of this server */ 87 const pr_netaddr_t *addr; 88 89 /* The listener for this server. Note that this listener, and that 90 * pointed to by ipbind->ib_listener (where ipbind->ib_server points to 91 * this server_rec) are the same. Ideally, we'd only want one pointer to 92 * the listener around, and avoid the duplication. To do this would 93 * require further structural changes. 94 */ 95 struct conn_struc *listen; 96 97 /* Configuration details */ 98 xaset_t *conf; 99 int config_type; 100 101 /* Internal server ID, automatically assigned */ 102 unsigned int sid; 103 104 /* Private data for passing among modules for this vhost. */ 105 pr_table_t *notes; 106 107 } server_rec; 108 109 typedef struct cmd_struc { 110 struct pool_rec *pool; 111 server_rec *server; 112 config_rec *config; 113 struct pool_rec *tmp_pool; /* Temporary pool which only exists 114 * while the cmd's handler is running 115 */ 116 unsigned int argc; 117 118 char *arg; /* entire argument (excluding command) */ 119 void **argv; 120 121 char *group; /* Command grouping */ 122 123 int cmd_class; /* The command class */ 124 125 /* These are used to speed up symbol hashing/lookups in stash.c. */ 126 int stash_index; 127 unsigned int stash_hash; 128 129 pr_table_t *notes; /* Private data for passing/retaining between handlers */ 130 131 int cmd_id; /* Index into commands list, for faster comparisons */ 132 133 /* If we detect that the client sent commands for a protocol OTHER than 134 * FTP, then this field will be FALSE; the protocol field will identify 135 * the detected protocol. 136 */ 137 int is_ftp; 138 const char *protocol; 139 140 } cmd_rec; 141 142 /* Operation codes for dir_* funcs */ 143 #define OP_HIDE 1 /* Op for hiding dirs/files */ 144 #define OP_COMMAND 2 /* Command operation */ 145 146 /* For the Order directive */ 147 #define ORDER_ALLOWDENY 0 148 #define ORDER_DENYALLOW 1 149 150 extern server_rec *main_server; 151 extern int tcpBackLog; 152 extern int SocketBindTight; 153 extern char ServerType; 154 extern unsigned long ServerMaxInstances; 155 extern int ServerUseReverseDNS; 156 157 /* These macros are used to help handle configuration in modules */ 158 #define CONF_ERROR(x, s) return PR_ERROR_MSG((x),NULL,pstrcat((x)->tmp_pool, \ 159 (x)->argv[0],": ",(s),NULL)); 160 161 #define CHECK_ARGS(x, n) if ((n) > 0 && (x)->argc > 0 && (x)->argc-1 < (n)) \ 162 CONF_ERROR(x,"missing parameters") 163 164 #define CHECK_VARARGS(x, n, m) if ((x)->argc - 1 < n || (x)->argc - 1 > m) \ 165 CONF_ERROR(x,"missing parameters") 166 167 #define CHECK_HASARGS(x, n) ((x)->argc - 1) == (n) 168 169 #define CHECK_CONF(x,p) if (!check_context((x),(p))) \ 170 CONF_ERROR((x), \ 171 pstrcat((x)->tmp_pool,"directive not allowed in ", \ 172 get_context_name((x)), \ 173 " context",NULL)) 174 175 #define CHECK_CMD_ARGS(x, n) \ 176 if ((x)->argc != (n)) { \ 177 pr_response_add_err(R_501, _("Invalid number of parameters")); \ 178 return PR_ERROR((x)); \ 179 } 180 181 #define CHECK_CMD_MIN_ARGS(x, n) \ 182 if ((x)->argc < (n)) { \ 183 pr_response_add_err(R_501, _("Invalid number of parameters")); \ 184 return PR_ERROR((x)); \ 185 } 186 187 /* Prototypes */ 188 189 /* KLUDGE: disable umask() for not G_WRITE operations. Config/ 190 * Directory walking code will be completely redesigned in 1.3, 191 * this is only necessary for performance reasons in 1.1/1.2 192 */ 193 void kludge_disable_umask(void); 194 void kludge_enable_umask(void); 195 196 int pr_define_add(const char *, int); 197 unsigned char pr_define_exists(const char *); 198 199 int fixup_servers(xaset_t *list); 200 xaset_t *get_dir_ctxt(pool *, char *); 201 202 /* Returns the buffer size to use for data transfers, regardless of IO 203 * direction. 204 */ 205 int pr_config_get_xfer_bufsz(void); 206 207 /* Returns the buffer size to use for data transfers given an IO direction 208 * (either PR_NETIO_IO_RD for reads/uploads, or PR_NETIO_IO_WR for 209 * writes/downloads). 210 */ 211 int pr_config_get_xfer_bufsz2(int); 212 213 /* Returns the buffer size to use for data transfers given an IO direction 214 * (either PR_NETIO_IO_RD for reads/uploads, or PR_NETIO_IO_WR for 215 * writes/downloads). This takes into account any server-specific buffer 216 * sizes, e.g. as configured via SocketOptions. 217 */ 218 int pr_config_get_server_xfer_bufsz(int); 219 220 config_rec *dir_match_path(pool *, char *); 221 void build_dyn_config(pool *, const char *, struct stat *, unsigned char); 222 unsigned char dir_hide_file(const char *); 223 int dir_check_full(pool *, cmd_rec *, const char *, const char *, int *); 224 int dir_check_limits(cmd_rec *, config_rec *, const char *, int); 225 int dir_check(pool *, cmd_rec *, const char *, const char *, int *); 226 int dir_check_canon(pool *, cmd_rec *, const char *, const char *, int *); 227 int is_dotdir(const char *); 228 int login_check_limits(xaset_t *, int, int, int *); 229 void resolve_anonymous_dirs(xaset_t *); 230 void resolve_deferred_dirs(server_rec *); 231 void fixup_dirs(server_rec *, int); 232 unsigned char check_context(cmd_rec *, int); 233 char *get_context_name(cmd_rec *); 234 int get_boolean(cmd_rec *, int); 235 const char *get_full_cmd(cmd_rec *); 236 237 /* Internal use only. */ 238 void init_dirtree(void); 239 240 #ifdef PR_USE_DEVEL 241 void pr_dirs_dump(void (*)(const char *, ...), xaset_t *, char *); 242 #endif /* PR_USE_DEVEL */ 243 244 #endif /* PR_DIRTREE_H */ 245