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 server's execution identity, or the user and group which
61 to change from root when server starts */
65 } SilcConfigServerSectionIdentity;
67 /* Holds all the configured log files. */
68 typedef struct SilcConfigServerSectionLoggingStruct {
72 struct SilcConfigServerSectionLoggingStruct *next;
73 struct SilcConfigServerSectionLoggingStruct *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 } SilcConfigServerSectionLogging;
82 /* Holds all configured connection classes */
83 typedef struct SilcConfigServerSectionConnectionClassStruct {
85 unsigned int ping_freq;
86 unsigned int connect_freq;
87 unsigned int max_links;
88 struct SilcConfigServerSectionConnectionClassStruct *next;
89 struct SilcConfigServerSectionConnectionClassStruct *prev;
90 } SilcConfigServerSectionConnectionClass;
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 SilcConfigServerSectionClientConnectionStruct {
102 struct SilcConfigServerSectionClientConnectionStruct *next;
103 struct SilcConfigServerSectionClientConnectionStruct *prev;
104 } SilcConfigServerSectionClientConnection;
106 /* Hols all server's administrators authentication data from config file */
107 typedef struct SilcConfigServerSectionAdminConnectionStruct {
113 struct SilcConfigServerSectionAdminConnectionStruct *next;
114 struct SilcConfigServerSectionAdminConnectionStruct *prev;
115 } SilcConfigServerSectionAdminConnection;
117 /* Holds all configured server/router connections from config file */
118 typedef struct SilcConfigServerSectionServerConnectionStruct {
126 struct SilcConfigServerSectionServerConnectionStruct *next;
127 struct SilcConfigServerSectionServerConnectionStruct *prev;
128 } SilcConfigServerSectionServerConnection;
130 /* Holds all configured denied connections from config file */
136 } SilcConfigServerSectionDenyConnection;
138 /* Holds all client redirections from config file */
142 } SilcConfigServerSectionRedirectClient;
144 /* Holds motd file */
147 } SilcConfigServerSectionMotd;
150 SILC Server Config object.
152 This object holds all the data parsed from the SILC server configuration
153 file. This is mainly used at the initialization of the server.
157 /* Pointer back to the server */
160 /* Filename of the configuration file */
163 /* Configuration sections */
164 SilcConfigServerSectionAlg *cipher;
165 SilcConfigServerSectionAlg *pkcs;
166 SilcConfigServerSectionAlg *hash_func;
167 SilcConfigServerSectionServerInfo *server_info;
168 SilcConfigServerSectionAdminInfo *admin_info;
169 SilcConfigServerSectionListenPort *listen_port;
170 SilcConfigServerSectionIdentity *identity;
171 SilcConfigServerSectionLogging *logging;
172 SilcConfigServerSectionConnectionClass *conn_class;
173 SilcConfigServerSectionClientConnection *clients;
174 SilcConfigServerSectionServerConnection *servers;
175 SilcConfigServerSectionServerConnection *routers;
176 SilcConfigServerSectionAdminConnection *admins;
177 SilcConfigServerSectionDenyConnection *denied;
178 SilcConfigServerSectionRedirectClient *redirect;
179 SilcConfigServerSectionMotd *motd;
180 } SilcConfigServerObject;
182 typedef SilcConfigServerObject *SilcConfigServer;
184 /* Configuration section type enumerations. */
186 SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
187 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
188 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
189 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
190 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
191 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
192 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
193 SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
194 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
195 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
196 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
197 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
198 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
199 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
200 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
201 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT,
202 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
203 } SilcConfigServerSectionType;
205 /* SILC Configuration Section structure. */
208 SilcConfigServerSectionType type;
209 unsigned int maxfields;
210 } SilcConfigServerSection;
212 /* LIst of all possible config sections in SILC server. */
213 extern SilcConfigServerSection silc_config_server_sections[];
215 /* Structure used in parsing the configuration lines. The line is read
216 from a file to this structure before parsing it further. */
217 typedef struct SilcConfigServerParseStruct {
219 unsigned int linenum;
220 SilcConfigServerSection *section;
221 struct SilcConfigServerParseStruct *next;
222 struct SilcConfigServerParseStruct *prev;
223 } *SilcConfigServerParse;
227 /* Allocates list entries for configuration sections. Used by all
228 config sections as this is common. */
229 #define SILC_SERVER_CONFIG_LIST_ALLOC(x) \
232 (x) = silc_calloc(1, sizeof(*(x))); \
237 (x)->next = silc_calloc(1, sizeof(*(x)->next)); \
238 (x)->next->next = NULL; \
239 (x)->next->prev = (x); \
246 SilcConfigServer silc_config_server_alloc(char *filename);
247 void silc_config_server_free(SilcConfigServer config);
248 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
249 SilcConfigServerParse *return_config);
250 int silc_config_server_parse_lines(SilcConfigServer config,
251 SilcConfigServerParse parse_config);
252 int silc_config_server_check_sections(unsigned int checkmask);
253 void silc_config_server_setlogfiles(SilcConfigServer config);
254 void silc_config_server_register_ciphers(SilcConfigServer config);
255 void silc_config_server_register_pkcs(SilcConfigServer config);
256 void silc_config_server_register_hashfuncs(SilcConfigServer config);
257 SilcConfigServerSectionClientConnection *
258 silc_config_server_find_client_conn(SilcConfigServer config,
259 char *host, int port);
260 SilcConfigServerSectionServerConnection *
261 silc_config_server_find_server_conn(SilcConfigServer config,
262 char *host, int port);
263 SilcConfigServerSectionServerConnection *
264 silc_config_server_find_router_conn(SilcConfigServer config,
265 char *host, int port);
266 void silc_config_server_print();