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 SilcConfigServerSectionAlgStruct {
28 unsigned int block_len;
30 struct SilcConfigServerSectionAlgStruct *next;
31 struct SilcConfigServerSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcConfigServerSectionAlg;
35 /* Holds server information from config file */
41 } SilcConfigServerSectionServerInfo;
43 /* Holds server's administrative information from config file */
49 } SilcConfigServerSectionAdminInfo;
51 /* Holds all the ports the server is listenning on */
52 typedef struct SilcConfigServerSectionListenPortStruct {
56 struct SilcConfigServerSectionListenPortStruct *next;
57 struct SilcConfigServerSectionListenPortStruct *prev;
58 } SilcConfigServerSectionListenPort;
60 /* Holds all the configured log files. */
61 typedef struct SilcConfigServerSectionLoggingStruct {
65 struct SilcConfigServerSectionLoggingStruct *next;
66 struct SilcConfigServerSectionLoggingStruct *prev;
68 /* Allowed <Logging> section types */
69 #define SILC_CONFIG_SERVER_LF_INFO "infologfile"
70 #define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile"
71 #define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile"
72 #define SILC_CONFIG_SERVER_LF_FATAL "fatalogfile"
73 } SilcConfigServerSectionLogging;
75 /* Holds all configured connection classes */
76 typedef struct SilcConfigServerSectionConnectionClassStruct {
78 unsigned int ping_freq;
79 unsigned int connect_freq;
80 unsigned int max_links;
81 struct SilcConfigServerSectionConnectionClassStruct *next;
82 struct SilcConfigServerSectionConnectionClassStruct *prev;
83 } SilcConfigServerSectionConnectionClass;
85 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
86 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
88 /* Holds all client authentication data from config file */
89 typedef struct SilcConfigServerSectionClientConnectionStruct {
95 struct SilcConfigServerSectionClientConnectionStruct *next;
96 struct SilcConfigServerSectionClientConnectionStruct *prev;
97 } SilcConfigServerSectionClientConnection;
99 /* Hols all server's administrators authentication data from config file */
100 typedef struct SilcConfigServerSectionAdminConnectionStruct {
106 struct SilcConfigServerSectionAdminConnectionStruct *next;
107 struct SilcConfigServerSectionAdminConnectionStruct *prev;
108 } SilcConfigServerSectionAdminConnection;
110 /* Holds all configured server/router connections from config file */
111 typedef struct SilcConfigServerSectionServerConnectionStruct {
119 struct SilcConfigServerSectionServerConnectionStruct *next;
120 struct SilcConfigServerSectionServerConnectionStruct *prev;
121 } SilcConfigServerSectionServerConnection;
123 /* Holds all configured denied connections from config file */
129 } SilcConfigServerSectionDenyConnection;
131 /* Holds all client redirections from config file */
135 } SilcConfigServerSectionRedirectClient;
137 /* Holds motd file */
140 } SilcConfigServerSectionMotd;
143 SILC Server Config object.
145 This object holds all the data parsed from the SILC server configuration
146 file. This is mainly used at the initialization of the server.
150 /* Pointer back to the server */
153 /* Filename of the configuration file */
156 /* Configuration sections */
157 SilcConfigServerSectionAlg *cipher;
158 SilcConfigServerSectionAlg *pkcs;
159 SilcConfigServerSectionAlg *hash_func;
160 SilcConfigServerSectionServerInfo *server_info;
161 SilcConfigServerSectionAdminInfo *admin_info;
162 SilcConfigServerSectionListenPort *listen_port;
163 SilcConfigServerSectionLogging *logging;
164 SilcConfigServerSectionConnectionClass *conn_class;
165 SilcConfigServerSectionClientConnection *clients;
166 SilcConfigServerSectionServerConnection *servers;
167 SilcConfigServerSectionServerConnection *routers;
168 SilcConfigServerSectionAdminConnection *admins;
169 SilcConfigServerSectionDenyConnection *denied;
170 SilcConfigServerSectionRedirectClient *redirect;
171 SilcConfigServerSectionMotd *motd;
172 } SilcConfigServerObject;
174 typedef SilcConfigServerObject *SilcConfigServer;
176 /* Configuration section type enumerations. */
178 SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
179 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
180 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
181 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
182 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
183 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
184 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
185 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
186 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
187 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
188 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
189 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
190 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
191 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
192 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT,
193 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
194 } SilcConfigServerSectionType;
196 /* SILC Configuration Section structure. */
199 SilcConfigServerSectionType type;
200 unsigned int maxfields;
201 } SilcConfigServerSection;
203 /* LIst of all possible config sections in SILC server. */
204 extern SilcConfigServerSection silc_config_server_sections[];
206 /* Structure used in parsing the configuration lines. The line is read
207 from a file to this structure before parsing it further. */
208 typedef struct SilcConfigServerParseStruct {
210 unsigned int linenum;
211 SilcConfigServerSection *section;
212 struct SilcConfigServerParseStruct *next;
213 struct SilcConfigServerParseStruct *prev;
214 } *SilcConfigServerParse;
218 /* Allocates list entries for configuration sections. Used by all
219 config sections as this is common. */
220 #define SILC_SERVER_CONFIG_LIST_ALLOC(x) \
223 (x) = silc_calloc(1, sizeof(*(x))); \
228 (x)->next = silc_calloc(1, sizeof(*(x)->next)); \
229 (x)->next->next = NULL; \
230 (x)->next->prev = (x); \
237 SilcConfigServer silc_config_server_alloc(char *filename);
238 void silc_config_server_free(SilcConfigServer config);
239 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
240 SilcConfigServerParse *return_config);
241 int silc_config_server_parse_lines(SilcConfigServer config,
242 SilcConfigServerParse parse_config);
243 int silc_config_server_check_sections(unsigned int checkmask);
244 void silc_config_server_setlogfiles(SilcConfigServer config);
245 void silc_config_server_register_ciphers(SilcConfigServer config);
246 void silc_config_server_register_pkcs(SilcConfigServer config);
247 void silc_config_server_register_hashfuncs(SilcConfigServer config);
248 SilcConfigServerSectionClientConnection *
249 silc_config_server_find_client_conn(SilcConfigServer config,
250 char *host, int port);
251 SilcConfigServerSectionServerConnection *
252 silc_config_server_find_server_conn(SilcConfigServer config,
253 char *host, int port);
254 SilcConfigServerSectionServerConnection *
255 silc_config_server_find_router_conn(SilcConfigServer config,
256 char *host, int port);
257 void silc_config_server_print();