1 /* 2 * ProFTPD - FTP server daemon 3 * Copyright (c) 2014-2016 The ProFTPD Project team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 * 19 * As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu 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 /* Configuration database API. */ 26 27 #ifndef PR_CONFIGDB_H 28 #define PR_CONFIGDB_H 29 30 #include "pool.h" 31 #include "sets.h" 32 #include "table.h" 33 34 typedef struct config_struc config_rec; 35 struct server_struc; 36 37 struct config_struc { 38 struct config_struc *next, *prev; 39 40 int config_type; 41 unsigned int config_id; 42 43 struct pool_rec *pool; /* Memory pool for this object */ 44 xaset_t *set; /* The set we are stored in */ 45 char *name; 46 unsigned int argc; 47 void **argv; 48 49 long flags; /* Flags */ 50 51 struct server_struc *server; /* Server this config element is attached to */ 52 config_rec *parent; /* Our parent configuration record */ 53 xaset_t *subset; /* Sub-configuration */ 54 }; 55 56 #define CONF_ROOT (1 << 0) /* No conf record */ 57 #define CONF_DIR (1 << 1) /* Per-Dir configuration */ 58 #define CONF_ANON (1 << 2) /* Anon. FTP configuration */ 59 #define CONF_LIMIT (1 << 3) /* Limits commands available */ 60 #define CONF_VIRTUAL (1 << 4) /* Virtual host */ 61 #define CONF_DYNDIR (1 << 5) /* .ftpaccess file */ 62 #define CONF_GLOBAL (1 << 6) /* "Global" context (applies to main server and ALL virtualhosts */ 63 #define CONF_CLASS (1 << 7) /* Class context */ 64 #define CONF_NAMED (1 << 8) /* Named virtual host */ 65 #define CONF_USERDATA (1 << 14) /* Runtime user data */ 66 #define CONF_PARAM (1 << 15) /* config/args pair */ 67 68 /* config_rec flags */ 69 #define CF_MERGEDOWN (1 << 0) /* Merge option down */ 70 #define CF_MERGEDOWN_MULTI (1 << 1) /* Merge down, allowing multiple instances */ 71 #define CF_DYNAMIC (1 << 2) /* Dynamically added entry */ 72 #define CF_DEFER (1 << 3) /* Defer hashing until authentication */ 73 #define CF_SILENT (1 << 4) /* Do not print a config dump when merging */ 74 #define CF_MULTI (1 << 5) /* Allow multiple instances, but do not merge down */ 75 76 /* The following macro determines the "highest" level available for 77 * configuration directives. If a current dir_config is available, it's 78 * subset is used, otherwise anon config or main server 79 */ 80 81 #define CURRENT_CONF (session.dir_config ? session.dir_config->subset \ 82 : (session.anon_config ? session.anon_config->subset \ 83 : main_server ? main_server->conf : NULL)) 84 #define TOPLEVEL_CONF (session.anon_config ? session.anon_config->subset : (main_server ? main_server->conf : NULL)) 85 86 /* Prototypes */ 87 88 config_rec *add_config_set(xaset_t **, const char *); 89 config_rec *add_config(struct server_struc *, const char *); 90 config_rec *add_config_param(const char *, unsigned int, ...); 91 config_rec *add_config_param_str(const char *, unsigned int, ...); 92 config_rec *add_config_param_set(xaset_t **, const char *, unsigned int, ...); 93 config_rec *pr_conf_add_server_config_param_str(struct server_struc *, 94 const char *, unsigned int, ...); 95 96 /* Flags used when searching for specific config_recs in the in-memory 97 * config database, particularly when 'recurse' is TRUE. 98 */ 99 #define PR_CONFIG_FIND_FL_SKIP_ANON 0x001 100 #define PR_CONFIG_FIND_FL_SKIP_DIR 0x002 101 #define PR_CONFIG_FIND_FL_SKIP_LIMIT 0x004 102 #define PR_CONFIG_FIND_FL_SKIP_DYNDIR 0x008 103 104 config_rec *find_config_next(config_rec *, config_rec *, int, 105 const char *, int); 106 config_rec *find_config_next2(config_rec *, config_rec *, int, 107 const char *, int, unsigned long); 108 config_rec *find_config(xaset_t *, int, const char *, int); 109 config_rec *find_config2(xaset_t *, int, const char *, int, unsigned long); 110 void find_config_set_top(config_rec *); 111 112 int remove_config(xaset_t *set, const char *name, int recurse); 113 114 #define PR_CONFIG_FL_INSERT_HEAD 0x001 115 #define PR_CONFIG_FL_PRESERVE_ENTRY 0x002 116 config_rec *pr_config_add_set(xaset_t **, const char *, int); 117 config_rec *pr_config_add(struct server_struc *, const char *, int); 118 int pr_config_remove(xaset_t *set, const char *name, int flags, int recurse); 119 120 /* Returns the assigned ID for the provided directive name, or zero 121 * if no ID mapping was found. 122 */ 123 unsigned int pr_config_get_id(const char *name); 124 125 /* Assigns a unique ID for the given configuration directive. The 126 * mapping of directive to ID is stored in a lookup table, so that 127 * searching of the config database by directive name can be done using 128 * ID comparisons rather than string comparisons. 129 * 130 * Returns the ID assigned for the given directive, or zero if there was an 131 * error. 132 */ 133 unsigned int pr_config_set_id(const char *name); 134 135 void *get_param_ptr(xaset_t *, const char *, int); 136 void *get_param_ptr_next(const char *, int); 137 138 void pr_config_merge_down(xaset_t *, int); 139 void pr_config_dump(void (*)(const char *, ...), xaset_t *, char *); 140 141 /* Internal use only. */ 142 void init_config(void); 143 144 #endif /* PR_CONFIGDB_H */ 145