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 #define SILC_CONFIG_SERVER_LO_QUICK "quicklogs"
87 #define SILC_CONFIG_SERVER_LO_FDELAY "flushdelay"
88 } SilcServerConfigSectionLogging;
89
90 /* Holds all configured connection classes */
91 typedef struct SilcServerConfigSectionConnectionClassStruct {
92   uint32 class;
93   uint32 ping_freq;
94   uint32 connect_freq;
95   uint32 max_links;
96   struct SilcServerConfigSectionConnectionClassStruct *next;
97   struct SilcServerConfigSectionConnectionClassStruct *prev;
98 } SilcServerConfigSectionConnectionClass;
99
100 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
101 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
102
103 /* Holds all client authentication data from config file */
104 typedef struct SilcServerConfigSectionClientConnectionStruct {
105   char *host;
106   SilcAuthMethod auth_meth;
107   void *auth_data;
108   uint32 auth_data_len;
109   uint16 port;
110   uint32 class;
111   struct SilcServerConfigSectionClientConnectionStruct *next;
112   struct SilcServerConfigSectionClientConnectionStruct *prev;
113 } SilcServerConfigSectionClientConnection;
114
115 /* Hols all server's administrators authentication data from config file */
116 typedef struct SilcServerConfigSectionAdminConnectionStruct {
117   char *host;
118   char *username;
119   char *nickname;
120   SilcAuthMethod auth_meth;
121   void *auth_data;
122   uint32 auth_data_len;
123   struct SilcServerConfigSectionAdminConnectionStruct *next;
124   struct SilcServerConfigSectionAdminConnectionStruct *prev;
125 } SilcServerConfigSectionAdminConnection;
126
127 /* Holds all configured server/router connections from config file */
128 typedef struct SilcServerConfigSectionServerConnectionStruct {
129   char *host;
130   SilcAuthMethod auth_meth;
131   void *auth_data;
132   uint32 auth_data_len;
133   uint16 port;
134   char *version;
135   uint32 class;
136   bool initiator;
137   bool backup_router;
138   char *backup_replace_ip;
139   uint16 backup_replace_port;
140   bool backup_local;
141   struct SilcServerConfigSectionServerConnectionStruct *next;
142   struct SilcServerConfigSectionServerConnectionStruct *prev;
143 } SilcServerConfigSectionServerConnection;
144
145 /* Holds all configured denied connections from config file */
146 typedef struct SilcServerConfigSectionDenyConnectionStruct {
147   char *host;
148   char *comment;
149   uint16 port;
150   struct SilcServerConfigSectionDenyConnectionStruct *next;
151   struct SilcServerConfigSectionDenyConnectionStruct *prev;
152 } SilcServerConfigSectionDenyConnection;
153
154 /* Holds motd file */
155 typedef struct {
156   char *motd_file;
157 } SilcServerConfigSectionMotd;
158
159 /* holds pid file */
160 typedef struct {
161    char *pid_file;
162 } SilcServerConfigSectionPid;
163
164 /* 
165    SILC Server Config object. 
166
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.
169
170 */
171 typedef struct {
172   /* Pointer back to the server */
173   void *server;
174
175   /* Filename of the configuration file */
176   char *filename;
177
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;
198
199 typedef SilcServerConfigObject *SilcServerConfig;
200
201 /* Configuration section type enumerations. */
202 typedef enum {
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;
223
224 /* SILC Configuration Section structure. */
225 typedef struct {
226   const char *section;
227   SilcServerConfigSectionType type;
228   int maxfields;
229 } SilcServerConfigSection;
230
231 /* LIst of all possible config sections in SILC server. */
232 extern SilcServerConfigSection silc_server_config_sections[];
233
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 {
237   SilcBuffer line;
238   int linenum;
239   SilcServerConfigSection *section;
240   struct SilcServerConfigParseStruct *next;
241   struct SilcServerConfigParseStruct *prev;
242 } *SilcServerConfigParse;
243
244 /* Macros */
245
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)                \
249 do {                                                    \
250   if (!(x)) {                                           \
251     (x) = silc_calloc(1, sizeof(*(x)));                 \
252     (x)->next = NULL;                                   \
253     (x)->prev = NULL;                                   \
254   } else {                                              \
255     if (!(x)->next) {                                   \
256       (x)->next = silc_calloc(1, sizeof(*(x)->next));   \
257       (x)->next->next = NULL;                           \
258       (x)->next->prev = (x);                            \
259       (x) = (x)->next;                                  \
260     }                                                   \
261   }                                                     \
262 } while(0)
263
264 /* Prototypes */
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,
294                                int port);
295
296 #endif