updates.
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef SERVERCONFIG_H
22 #define SERVERCONFIG_H
23
24 /* Holds information of configured algorithms */
25 typedef struct SilcServerConfigSectionAlgStruct {
26   char *alg_name;
27   char *sim_name;
28   uint32 block_len;
29   uint32 key_len;
30   struct SilcServerConfigSectionAlgStruct *next;
31   struct SilcServerConfigSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcServerConfigSectionAlg;
34
35 /* Holds server keys from config file */
36 typedef struct {
37   SilcPublicKey public_key;
38   SilcPrivateKey private_key;
39 } SilcServerConfigSectionServerKeys;
40
41 /* Holds server information from config file */
42 typedef struct {
43   char *server_name;
44   char *server_ip;
45   char *location;
46   uint16 port;
47 } SilcServerConfigSectionServerInfo;
48
49 /* Holds server's administrative information from config file */
50 typedef struct {
51   char *location;
52   char *server_type;
53   char *admin_name;
54   char *admin_email;
55 } SilcServerConfigSectionAdminInfo;
56
57 /* Holds all the ports the server is listenning on */
58 typedef struct SilcServerConfigSectionListenPortStruct {
59   char *local_ip;
60   char *listener_ip;
61   uint16 port;
62   struct SilcServerConfigSectionListenPortStruct *next;
63   struct SilcServerConfigSectionListenPortStruct *prev;
64 } SilcServerConfigSectionListenPort;
65
66 /* Holds server's execution identity, or the user and group which
67    to change from root when server starts */
68 typedef struct {
69   char *user;
70   char *group;
71 } SilcServerConfigSectionIdentity;
72
73 /* Holds all the configured log files. */
74 typedef struct SilcServerConfigSectionLoggingStruct {
75   char *logtype;
76   char *filename;
77   uint32 maxsize;
78   struct SilcServerConfigSectionLoggingStruct *next;
79   struct SilcServerConfigSectionLoggingStruct *prev;
80
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;
87
88 /* Holds all configured connection classes */
89 typedef struct SilcServerConfigSectionConnectionClassStruct {
90   uint32 class;
91   uint32 ping_freq;
92   uint32 connect_freq;
93   uint32 max_links;
94   struct SilcServerConfigSectionConnectionClassStruct *next;
95   struct SilcServerConfigSectionConnectionClassStruct *prev;
96 } SilcServerConfigSectionConnectionClass;
97
98 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
99 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
100
101 /* Holds all client authentication data from config file */
102 typedef struct SilcServerConfigSectionClientConnectionStruct {
103   char *host;
104   SilcAuthMethod auth_meth;
105   void *auth_data;
106   uint32 auth_data_len;
107   uint16 port;
108   uint32 class;
109   struct SilcServerConfigSectionClientConnectionStruct *next;
110   struct SilcServerConfigSectionClientConnectionStruct *prev;
111 } SilcServerConfigSectionClientConnection;
112
113 /* Hols all server's administrators authentication data from config file */
114 typedef struct SilcServerConfigSectionAdminConnectionStruct {
115   char *host;
116   char *username;
117   char *nickname;
118   SilcAuthMethod auth_meth;
119   void *auth_data;
120   uint32 auth_data_len;
121   struct SilcServerConfigSectionAdminConnectionStruct *next;
122   struct SilcServerConfigSectionAdminConnectionStruct *prev;
123 } SilcServerConfigSectionAdminConnection;
124
125 /* Holds all configured server/router connections from config file */
126 typedef struct SilcServerConfigSectionServerConnectionStruct {
127   char *host;
128   SilcAuthMethod auth_meth;
129   void *auth_data;
130   uint32 auth_data_len;
131   uint16 port;
132   char *version;
133   uint32 class;
134   bool initiator;
135   bool backup_router;
136   char *backup_replace_ip;
137   uint16 backup_replace_port;
138   bool backup_local;
139   struct SilcServerConfigSectionServerConnectionStruct *next;
140   struct SilcServerConfigSectionServerConnectionStruct *prev;
141 } SilcServerConfigSectionServerConnection;
142
143 /* Holds all configured denied connections from config file */
144 typedef struct SilcServerConfigSectionDenyConnectionStruct {
145   char *host;
146   char *comment;
147   uint16 port;
148   struct SilcServerConfigSectionDenyConnectionStruct *next;
149   struct SilcServerConfigSectionDenyConnectionStruct *prev;
150 } SilcServerConfigSectionDenyConnection;
151
152 /* Holds motd file */
153 typedef struct {
154   char *motd_file;
155 } SilcServerConfigSectionMotd;
156
157 /* holds pid file */
158 typedef struct {
159    char *pid_file;
160 } SilcServerConfigSectionPid;
161
162 /* 
163    SILC Server Config object. 
164
165    This object holds all the data parsed from the SILC server configuration
166    file. This is mainly used at the initialization of the server.
167
168 */
169 typedef struct {
170   /* Pointer back to the server */
171   void *server;
172
173   /* Filename of the configuration file */
174   char *filename;
175
176   /* Configuration sections */
177   SilcServerConfigSectionAlg *cipher;
178   SilcServerConfigSectionAlg *pkcs;
179   SilcServerConfigSectionAlg *hash_func;
180   SilcServerConfigSectionAlg *hmac;
181   SilcServerConfigSectionServerKeys *server_keys;
182   SilcServerConfigSectionServerInfo *server_info;
183   SilcServerConfigSectionAdminInfo *admin_info;
184   SilcServerConfigSectionListenPort *listen_port;
185   SilcServerConfigSectionIdentity *identity;
186   SilcServerConfigSectionLogging *logging;
187   SilcServerConfigSectionConnectionClass *conn_class;
188   SilcServerConfigSectionClientConnection *clients;
189   SilcServerConfigSectionServerConnection *servers;
190   SilcServerConfigSectionServerConnection *routers;
191   SilcServerConfigSectionAdminConnection *admins;
192   SilcServerConfigSectionDenyConnection *denied;
193   SilcServerConfigSectionMotd *motd;
194   SilcServerConfigSectionPid *pidfile;
195 } SilcServerConfigObject;
196
197 typedef SilcServerConfigObject *SilcServerConfig;
198
199 /* Configuration section type enumerations. */
200 typedef enum {
201   SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
202   SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
203   SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
204   SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
205   SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
206   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_KEYS,
207   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
208   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
209   SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
210   SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
211   SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
212   SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
213   SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
214   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
215   SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
216   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
217   SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
218   SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
219   SILC_CONFIG_SERVER_SECTION_TYPE_PID,
220 } SilcServerConfigSectionType;
221
222 /* SILC Configuration Section structure. */
223 typedef struct {
224   const char *section;
225   SilcServerConfigSectionType type;
226   int maxfields;
227 } SilcServerConfigSection;
228
229 /* LIst of all possible config sections in SILC server. */
230 extern SilcServerConfigSection silc_server_config_sections[];
231
232 /* Structure used in parsing the configuration lines. The line is read
233    from a file to this structure before parsing it further. */
234 typedef struct SilcServerConfigParseStruct {
235   SilcBuffer line;
236   int linenum;
237   SilcServerConfigSection *section;
238   struct SilcServerConfigParseStruct *next;
239   struct SilcServerConfigParseStruct *prev;
240 } *SilcServerConfigParse;
241
242 /* Macros */
243
244 /* Allocates list entries for configuration sections. Used by all
245    config sections as this is common. */
246 #define SILC_SERVER_CONFIG_LIST_ALLOC(x)                \
247 do {                                                    \
248   if (!(x)) {                                           \
249     (x) = silc_calloc(1, sizeof(*(x)));                 \
250     (x)->next = NULL;                                   \
251     (x)->prev = NULL;                                   \
252   } else {                                              \
253     if (!(x)->next) {                                   \
254       (x)->next = silc_calloc(1, sizeof(*(x)->next));   \
255       (x)->next->next = NULL;                           \
256       (x)->next->prev = (x);                            \
257       (x) = (x)->next;                                  \
258     }                                                   \
259   }                                                     \
260 } while(0)
261
262 /* Prototypes */
263 SilcServerConfig silc_server_config_alloc(char *filename);
264 void silc_server_config_free(SilcServerConfig config);
265 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
266                              SilcServerConfigParse *return_config);
267 int silc_server_config_parse_lines(SilcServerConfig config, 
268                                    SilcServerConfigParse parse_config);
269 int silc_server_config_check_sections(uint32 checkmask);
270 void silc_server_config_setlogfiles(SilcServerConfig config, SilcSchedule sked);
271 bool silc_server_config_register_ciphers(SilcServerConfig config);
272 bool silc_server_config_register_pkcs(SilcServerConfig config);
273 bool silc_server_config_register_hashfuncs(SilcServerConfig config);
274 bool silc_server_config_register_hmacs(SilcServerConfig config);
275 SilcServerConfigSectionClientConnection *
276 silc_server_config_find_client_conn(SilcServerConfig config, 
277                                     char *host, int port);
278 SilcServerConfigSectionServerConnection *
279 silc_server_config_find_server_conn(SilcServerConfig config, 
280                                     char *host, int port);
281 SilcServerConfigSectionServerConnection *
282 silc_server_config_find_router_conn(SilcServerConfig config, 
283                                     char *host, int port);
284 bool silc_server_config_is_primary_route(SilcServerConfig config);
285 SilcServerConfigSectionServerConnection *
286 silc_server_config_get_primary_router(SilcServerConfig config);
287 SilcServerConfigSectionAdminConnection *
288 silc_server_config_find_admin(SilcServerConfig config,
289                               char *host, char *username, char *nickname);
290 SilcServerConfigSectionDenyConnection *
291 silc_server_config_denied_conn(SilcServerConfig config, char *host,
292                                int port);
293
294 #endif