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 #define SILC_CONFIG_SERVER_LO_QUICK "quicklogs"
87 #define SILC_CONFIG_SERVER_LO_FDELAY "flushdelay"
88 } SilcServerConfigSectionLogging;
90 /* Holds all configured connection classes */
91 typedef struct SilcServerConfigSectionConnectionClassStruct {
96 struct SilcServerConfigSectionConnectionClassStruct *next;
97 struct SilcServerConfigSectionConnectionClassStruct *prev;
98 } SilcServerConfigSectionConnectionClass;
100 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
101 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
103 /* Holds all client authentication data from config file */
104 typedef struct SilcServerConfigSectionClientConnectionStruct {
106 SilcAuthMethod auth_meth;
108 uint32 auth_data_len;
111 struct SilcServerConfigSectionClientConnectionStruct *next;
112 struct SilcServerConfigSectionClientConnectionStruct *prev;
113 } SilcServerConfigSectionClientConnection;
115 /* Hols all server's administrators authentication data from config file */
116 typedef struct SilcServerConfigSectionAdminConnectionStruct {
120 SilcAuthMethod auth_meth;
122 uint32 auth_data_len;
123 struct SilcServerConfigSectionAdminConnectionStruct *next;
124 struct SilcServerConfigSectionAdminConnectionStruct *prev;
125 } SilcServerConfigSectionAdminConnection;
127 /* Holds all configured server/router connections from config file */
128 typedef struct SilcServerConfigSectionServerConnectionStruct {
130 SilcAuthMethod auth_meth;
132 uint32 auth_data_len;
138 char *backup_replace_ip;
139 uint16 backup_replace_port;
141 struct SilcServerConfigSectionServerConnectionStruct *next;
142 struct SilcServerConfigSectionServerConnectionStruct *prev;
143 } SilcServerConfigSectionServerConnection;
145 /* Holds all configured denied connections from config file */
146 typedef struct SilcServerConfigSectionDenyConnectionStruct {
150 struct SilcServerConfigSectionDenyConnectionStruct *next;
151 struct SilcServerConfigSectionDenyConnectionStruct *prev;
152 } SilcServerConfigSectionDenyConnection;
154 /* Holds motd file */
157 } SilcServerConfigSectionMotd;
162 } SilcServerConfigSectionPid;
165 SILC Server Config object.
167 This object holds all the data parsed from the SILC server configuration
168 file. This is mainly used at the initialization of the server.
172 /* Pointer back to the server */
175 /* Filename of the configuration file */
178 /* Configuration sections */
179 SilcServerConfigSectionAlg *cipher;
180 SilcServerConfigSectionAlg *pkcs;
181 SilcServerConfigSectionAlg *hash_func;
182 SilcServerConfigSectionAlg *hmac;
183 SilcServerConfigSectionServerKeys *server_keys;
184 SilcServerConfigSectionServerInfo *server_info;
185 SilcServerConfigSectionAdminInfo *admin_info;
186 SilcServerConfigSectionListenPort *listen_port;
187 SilcServerConfigSectionIdentity *identity;
188 SilcServerConfigSectionLogging *logging;
189 SilcServerConfigSectionConnectionClass *conn_class;
190 SilcServerConfigSectionClientConnection *clients;
191 SilcServerConfigSectionServerConnection *servers;
192 SilcServerConfigSectionServerConnection *routers;
193 SilcServerConfigSectionAdminConnection *admins;
194 SilcServerConfigSectionDenyConnection *denied;
195 SilcServerConfigSectionMotd *motd;
196 SilcServerConfigSectionPid *pidfile;
197 } SilcServerConfigObject;
199 typedef SilcServerConfigObject *SilcServerConfig;
201 /* Configuration section type enumerations. */
203 SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
204 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
205 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
206 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
207 SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
208 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_KEYS,
209 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
210 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
211 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
212 SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
213 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
214 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
215 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
216 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
217 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
218 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
219 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
220 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
221 SILC_CONFIG_SERVER_SECTION_TYPE_PID,
222 } SilcServerConfigSectionType;
224 /* SILC Configuration Section structure. */
227 SilcServerConfigSectionType type;
229 } SilcServerConfigSection;
231 /* LIst of all possible config sections in SILC server. */
232 extern SilcServerConfigSection silc_server_config_sections[];
234 /* Structure used in parsing the configuration lines. The line is read
235 from a file to this structure before parsing it further. */
236 typedef struct SilcServerConfigParseStruct {
239 SilcServerConfigSection *section;
240 struct SilcServerConfigParseStruct *next;
241 struct SilcServerConfigParseStruct *prev;
242 } *SilcServerConfigParse;
246 /* Allocates list entries for configuration sections. Used by all
247 config sections as this is common. */
248 #define SILC_SERVER_CONFIG_LIST_ALLOC(x) \
251 (x) = silc_calloc(1, sizeof(*(x))); \
256 (x)->next = silc_calloc(1, sizeof(*(x)->next)); \
257 (x)->next->next = NULL; \
258 (x)->next->prev = (x); \
265 SilcServerConfig silc_server_config_alloc(char *filename);
266 void silc_server_config_free(SilcServerConfig config);
267 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
268 SilcServerConfigParse *return_config);
269 int silc_server_config_parse_lines(SilcServerConfig config,
270 SilcServerConfigParse parse_config);
271 int silc_server_config_check_sections(uint32 checkmask);
272 void silc_server_config_setlogfiles(SilcServerConfig config, SilcSchedule sked);
273 bool silc_server_config_register_ciphers(SilcServerConfig config);
274 bool silc_server_config_register_pkcs(SilcServerConfig config);
275 bool silc_server_config_register_hashfuncs(SilcServerConfig config);
276 bool silc_server_config_register_hmacs(SilcServerConfig config);
277 SilcServerConfigSectionClientConnection *
278 silc_server_config_find_client_conn(SilcServerConfig config,
279 char *host, int port);
280 SilcServerConfigSectionServerConnection *
281 silc_server_config_find_server_conn(SilcServerConfig config,
282 char *host, int port);
283 SilcServerConfigSectionServerConnection *
284 silc_server_config_find_router_conn(SilcServerConfig config,
285 char *host, int port);
286 bool silc_server_config_is_primary_route(SilcServerConfig config);
287 SilcServerConfigSectionServerConnection *
288 silc_server_config_get_primary_router(SilcServerConfig config);
289 SilcServerConfigSectionAdminConnection *
290 silc_server_config_find_admin(SilcServerConfig config,
291 char *host, char *username, char *nickname);
292 SilcServerConfigSectionDenyConnection *
293 silc_server_config_denied_conn(SilcServerConfig config, char *host,