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 {
28 unsigned int block_len;
30 struct SilcServerConfigSectionAlgStruct *next;
31 struct SilcServerConfigSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcServerConfigSectionAlg;
35 /* Holds server information from config file */
41 } SilcServerConfigSectionServerInfo;
43 /* Holds server's administrative information from config file */
49 } SilcServerConfigSectionAdminInfo;
51 /* Holds all the ports the server is listenning on */
52 typedef struct SilcServerConfigSectionListenPortStruct {
56 struct SilcServerConfigSectionListenPortStruct *next;
57 struct SilcServerConfigSectionListenPortStruct *prev;
58 } SilcServerConfigSectionListenPort;
60 /* Holds server's execution identity, or the user and group which
61 to change from root when server starts */
65 } SilcServerConfigSectionIdentity;
67 /* Holds all the configured log files. */
68 typedef struct SilcServerConfigSectionLoggingStruct {
72 struct SilcServerConfigSectionLoggingStruct *next;
73 struct SilcServerConfigSectionLoggingStruct *prev;
75 /* Allowed <Logging> section types */
76 #define SILC_CONFIG_SERVER_LF_INFO "infologfile"
77 #define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile"
78 #define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile"
79 #define SILC_CONFIG_SERVER_LF_FATAL "fatalogfile"
80 } SilcServerConfigSectionLogging;
82 /* Holds all configured connection classes */
83 typedef struct SilcServerConfigSectionConnectionClassStruct {
85 unsigned int ping_freq;
86 unsigned int connect_freq;
87 unsigned int max_links;
88 struct SilcServerConfigSectionConnectionClassStruct *next;
89 struct SilcServerConfigSectionConnectionClassStruct *prev;
90 } SilcServerConfigSectionConnectionClass;
92 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
93 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
95 /* Holds all client authentication data from config file */
96 typedef struct SilcServerConfigSectionClientConnectionStruct {
98 SilcAuthMethod auth_meth;
100 unsigned int auth_data_len;
103 struct SilcServerConfigSectionClientConnectionStruct *next;
104 struct SilcServerConfigSectionClientConnectionStruct *prev;
105 } SilcServerConfigSectionClientConnection;
107 /* Hols all server's administrators authentication data from config file */
108 typedef struct SilcServerConfigSectionAdminConnectionStruct {
112 SilcAuthMethod auth_meth;
114 unsigned int auth_data_len;
115 struct SilcServerConfigSectionAdminConnectionStruct *next;
116 struct SilcServerConfigSectionAdminConnectionStruct *prev;
117 } SilcServerConfigSectionAdminConnection;
119 /* Holds all configured server/router connections from config file */
120 typedef struct SilcServerConfigSectionServerConnectionStruct {
122 SilcAuthMethod auth_meth;
124 unsigned int auth_data_len;
129 struct SilcServerConfigSectionServerConnectionStruct *next;
130 struct SilcServerConfigSectionServerConnectionStruct *prev;
131 } SilcServerConfigSectionServerConnection;
133 /* Holds all configured denied connections from config file */
139 } SilcServerConfigSectionDenyConnection;
141 /* Holds all client redirections from config file */
145 } SilcServerConfigSectionRedirectClient;
147 /* Holds motd file */
150 } SilcServerConfigSectionMotd;
153 SILC Server Config object.
155 This object holds all the data parsed from the SILC server configuration
156 file. This is mainly used at the initialization of the server.
160 /* Pointer back to the server */
163 /* Filename of the configuration file */
166 /* Configuration sections */
167 SilcServerConfigSectionAlg *cipher;
168 SilcServerConfigSectionAlg *pkcs;
169 SilcServerConfigSectionAlg *hash_func;
170 SilcServerConfigSectionAlg *hmac;
171 SilcServerConfigSectionServerInfo *server_info;
172 SilcServerConfigSectionAdminInfo *admin_info;
173 SilcServerConfigSectionListenPort *listen_port;
174 SilcServerConfigSectionIdentity *identity;
175 SilcServerConfigSectionLogging *logging;
176 SilcServerConfigSectionConnectionClass *conn_class;
177 SilcServerConfigSectionClientConnection *clients;
178 SilcServerConfigSectionServerConnection *servers;
179 SilcServerConfigSectionServerConnection *routers;
180 SilcServerConfigSectionAdminConnection *admins;
181 SilcServerConfigSectionDenyConnection *denied;
182 SilcServerConfigSectionRedirectClient *redirect;
183 SilcServerConfigSectionMotd *motd;
184 } SilcServerConfigObject;
186 typedef SilcServerConfigObject *SilcServerConfig;
188 /* Configuration section type enumerations. */
190 SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
191 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
192 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
193 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
194 SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
195 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
196 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
197 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
198 SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
199 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
200 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
201 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
202 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
203 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
204 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
205 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
206 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT,
207 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
208 } SilcServerConfigSectionType;
210 /* SILC Configuration Section structure. */
213 SilcServerConfigSectionType type;
214 unsigned int maxfields;
215 } SilcServerConfigSection;
217 /* LIst of all possible config sections in SILC server. */
218 extern SilcServerConfigSection silc_server_config_sections[];
220 /* Structure used in parsing the configuration lines. The line is read
221 from a file to this structure before parsing it further. */
222 typedef struct SilcServerConfigParseStruct {
224 unsigned int linenum;
225 SilcServerConfigSection *section;
226 struct SilcServerConfigParseStruct *next;
227 struct SilcServerConfigParseStruct *prev;
228 } *SilcServerConfigParse;
232 /* Allocates list entries for configuration sections. Used by all
233 config sections as this is common. */
234 #define SILC_SERVER_CONFIG_LIST_ALLOC(x) \
237 (x) = silc_calloc(1, sizeof(*(x))); \
242 (x)->next = silc_calloc(1, sizeof(*(x)->next)); \
243 (x)->next->next = NULL; \
244 (x)->next->prev = (x); \
251 SilcServerConfig silc_server_config_alloc(char *filename);
252 void silc_server_config_free(SilcServerConfig config);
253 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
254 SilcServerConfigParse *return_config);
255 int silc_server_config_parse_lines(SilcServerConfig config,
256 SilcServerConfigParse parse_config);
257 int silc_server_config_check_sections(unsigned int checkmask);
258 void silc_server_config_setlogfiles(SilcServerConfig config);
259 void silc_server_config_register_ciphers(SilcServerConfig config);
260 void silc_server_config_register_pkcs(SilcServerConfig config);
261 void silc_server_config_register_hashfuncs(SilcServerConfig config);
262 void silc_server_config_register_hmacs(SilcServerConfig config);
263 SilcServerConfigSectionClientConnection *
264 silc_server_config_find_client_conn(SilcServerConfig config,
265 char *host, int port);
266 SilcServerConfigSectionServerConnection *
267 silc_server_config_find_server_conn(SilcServerConfig config,
268 char *host, int port);
269 SilcServerConfigSectionServerConnection *
270 silc_server_config_find_router_conn(SilcServerConfig config,
271 char *host, int port);
272 SilcServerConfigSectionAdminConnection *
273 silc_server_config_find_admin(SilcServerConfig config,
274 char *host, char *username, char *nickname);
275 void silc_server_config_print();