5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 #ifndef SERVERCONFIG_H
22 #define SERVERCONFIG_H
24 /* Holds information of configured algorithms */
25 typedef struct SilcServerConfigSectionAlgStruct {
30 struct SilcServerConfigSectionAlgStruct *next;
31 struct SilcServerConfigSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcServerConfigSectionAlg;
35 /* Holds server keys from config file */
37 SilcPublicKey public_key;
38 SilcPrivateKey private_key;
39 } SilcServerConfigSectionServerKeys;
41 /* Holds server information from config file */
47 } SilcServerConfigSectionServerInfo;
49 /* Holds server's administrative information from config file */
55 } SilcServerConfigSectionAdminInfo;
57 /* Holds all the ports the server is listenning on */
58 typedef struct SilcServerConfigSectionListenPortStruct {
62 struct SilcServerConfigSectionListenPortStruct *next;
63 struct SilcServerConfigSectionListenPortStruct *prev;
64 } SilcServerConfigSectionListenPort;
66 /* Holds server's execution identity, or the user and group which
67 to change from root when server starts */
71 } SilcServerConfigSectionIdentity;
73 /* Holds all the configured log files. */
74 typedef struct SilcServerConfigSectionLoggingStruct {
78 struct SilcServerConfigSectionLoggingStruct *next;
79 struct SilcServerConfigSectionLoggingStruct *prev;
81 /* Allowed <Logging> section types */
82 #define SILC_CONFIG_SERVER_LF_INFO "infologfile"
83 #define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile"
84 #define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile"
85 #define SILC_CONFIG_SERVER_LF_FATAL "fatallogfile"
86 } SilcServerConfigSectionLogging;
88 /* Holds all configured connection classes */
89 typedef struct SilcServerConfigSectionConnectionClassStruct {
94 struct SilcServerConfigSectionConnectionClassStruct *next;
95 struct SilcServerConfigSectionConnectionClassStruct *prev;
96 } SilcServerConfigSectionConnectionClass;
98 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
99 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
101 /* Holds all client authentication data from config file */
102 typedef struct SilcServerConfigSectionClientConnectionStruct {
104 SilcAuthMethod auth_meth;
106 uint32 auth_data_len;
109 struct SilcServerConfigSectionClientConnectionStruct *next;
110 struct SilcServerConfigSectionClientConnectionStruct *prev;
111 } SilcServerConfigSectionClientConnection;
113 /* Hols all server's administrators authentication data from config file */
114 typedef struct SilcServerConfigSectionAdminConnectionStruct {
118 SilcAuthMethod auth_meth;
120 uint32 auth_data_len;
121 struct SilcServerConfigSectionAdminConnectionStruct *next;
122 struct SilcServerConfigSectionAdminConnectionStruct *prev;
123 } SilcServerConfigSectionAdminConnection;
125 /* Holds all configured server/router connections from config file */
126 typedef struct SilcServerConfigSectionServerConnectionStruct {
128 SilcAuthMethod auth_meth;
130 uint32 auth_data_len;
136 char *backup_replace_ip;
137 uint16 backup_replace_port;
139 struct SilcServerConfigSectionServerConnectionStruct *next;
140 struct SilcServerConfigSectionServerConnectionStruct *prev;
141 } SilcServerConfigSectionServerConnection;
143 /* Holds all configured denied connections from config file */
144 typedef struct SilcServerConfigSectionDenyConnectionStruct {
148 struct SilcServerConfigSectionDenyConnectionStruct *next;
149 struct SilcServerConfigSectionDenyConnectionStruct *prev;
150 } SilcServerConfigSectionDenyConnection;
152 /* Holds motd file */
155 } SilcServerConfigSectionMotd;
158 SILC Server Config object.
160 This object holds all the data parsed from the SILC server configuration
161 file. This is mainly used at the initialization of the server.
165 /* Pointer back to the server */
168 /* Filename of the configuration file */
171 /* Configuration sections */
172 SilcServerConfigSectionAlg *cipher;
173 SilcServerConfigSectionAlg *pkcs;
174 SilcServerConfigSectionAlg *hash_func;
175 SilcServerConfigSectionAlg *hmac;
176 SilcServerConfigSectionServerKeys *server_keys;
177 SilcServerConfigSectionServerInfo *server_info;
178 SilcServerConfigSectionAdminInfo *admin_info;
179 SilcServerConfigSectionListenPort *listen_port;
180 SilcServerConfigSectionIdentity *identity;
181 SilcServerConfigSectionLogging *logging;
182 SilcServerConfigSectionConnectionClass *conn_class;
183 SilcServerConfigSectionClientConnection *clients;
184 SilcServerConfigSectionServerConnection *servers;
185 SilcServerConfigSectionServerConnection *routers;
186 SilcServerConfigSectionAdminConnection *admins;
187 SilcServerConfigSectionDenyConnection *denied;
188 SilcServerConfigSectionMotd *motd;
189 } SilcServerConfigObject;
191 typedef SilcServerConfigObject *SilcServerConfig;
193 /* Configuration section type enumerations. */
195 SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
196 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
197 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
198 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
199 SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
200 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_KEYS,
201 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
202 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
203 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
204 SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
205 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
206 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
207 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
208 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
209 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
210 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
211 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
212 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
213 } SilcServerConfigSectionType;
215 /* SILC Configuration Section structure. */
218 SilcServerConfigSectionType type;
220 } SilcServerConfigSection;
222 /* LIst of all possible config sections in SILC server. */
223 extern SilcServerConfigSection silc_server_config_sections[];
225 /* Structure used in parsing the configuration lines. The line is read
226 from a file to this structure before parsing it further. */
227 typedef struct SilcServerConfigParseStruct {
230 SilcServerConfigSection *section;
231 struct SilcServerConfigParseStruct *next;
232 struct SilcServerConfigParseStruct *prev;
233 } *SilcServerConfigParse;
237 /* Allocates list entries for configuration sections. Used by all
238 config sections as this is common. */
239 #define SILC_SERVER_CONFIG_LIST_ALLOC(x) \
242 (x) = silc_calloc(1, sizeof(*(x))); \
247 (x)->next = silc_calloc(1, sizeof(*(x)->next)); \
248 (x)->next->next = NULL; \
249 (x)->next->prev = (x); \
256 SilcServerConfig silc_server_config_alloc(char *filename);
257 void silc_server_config_free(SilcServerConfig config);
258 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
259 SilcServerConfigParse *return_config);
260 int silc_server_config_parse_lines(SilcServerConfig config,
261 SilcServerConfigParse parse_config);
262 int silc_server_config_check_sections(uint32 checkmask);
263 void silc_server_config_setlogfiles(SilcServerConfig config);
264 bool silc_server_config_register_ciphers(SilcServerConfig config);
265 bool silc_server_config_register_pkcs(SilcServerConfig config);
266 bool silc_server_config_register_hashfuncs(SilcServerConfig config);
267 bool silc_server_config_register_hmacs(SilcServerConfig config);
268 SilcServerConfigSectionClientConnection *
269 silc_server_config_find_client_conn(SilcServerConfig config,
270 char *host, int port);
271 SilcServerConfigSectionServerConnection *
272 silc_server_config_find_server_conn(SilcServerConfig config,
273 char *host, int port);
274 SilcServerConfigSectionServerConnection *
275 silc_server_config_find_router_conn(SilcServerConfig config,
276 char *host, int port);
277 bool silc_server_config_is_primary_route(SilcServerConfig config);
278 SilcServerConfigSectionServerConnection *
279 silc_server_config_get_primary_router(SilcServerConfig config);
280 SilcServerConfigSectionAdminConnection *
281 silc_server_config_find_admin(SilcServerConfig config,
282 char *host, char *username, char *nickname);
283 SilcServerConfigSectionDenyConnection *
284 silc_server_config_denied_conn(SilcServerConfig config, char *host,