Merged silc_1_1_branch to trunk.
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Giovanni Giacobbi <giovanni@giacobbi.net>
6
7   Copyright (C) 1997 - 2007 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SERVERCONFIG_H
21 #define SERVERCONFIG_H
22
23 typedef struct SilcServerConfigCipherStruct {
24   char *name;
25   char *module;
26   SilcUInt32 key_length;
27   SilcUInt32 block_length;
28   struct SilcServerConfigCipherStruct *next;
29 } SilcServerConfigCipher;
30
31 typedef struct SilcServerConfigHashStruct {
32   char *name;
33   char *module;
34   SilcUInt32 block_length;
35   SilcUInt32 digest_length;
36   struct SilcServerConfigHashStruct *next;
37 } SilcServerConfigHash;
38
39 typedef struct SilcServerConfigHmacStruct {
40   char *name;
41   char *hash;
42   SilcUInt32 mac_length;
43   struct SilcServerConfigHmacStruct *next;
44 } SilcServerConfigHmac;
45
46 typedef struct SilcServerConfigPkcsStruct {
47   char *name;
48   struct SilcServerConfigPkcsStruct *next;
49 } SilcServerConfigPkcs;
50
51 typedef struct SilcServerConfigServerInfoInterfaceStruct {
52   char *server_ip;
53   char *public_ip;
54   SilcUInt16 port;
55   struct SilcServerConfigServerInfoInterfaceStruct *next;
56 } SilcServerConfigServerInfoInterface;
57
58 typedef struct SilcServerConfigServerInfoStruct {
59   char *server_name;
60   SilcServerConfigServerInfoInterface *primary;
61   SilcServerConfigServerInfoInterface *secondary;
62   char *server_type;    /* E.g. "Test Server" */
63   char *location;       /* geographic location */
64   char *admin;          /* admin full name */
65   char *email;          /* admin's email address */
66   char *user;           /* userid the server should be runned at */
67   char *group;          /* ditto, but about groupid */
68   SilcPublicKey public_key;
69   SilcPrivateKey private_key;
70   char *motd_file;      /* path to text motd file (reading only) */
71   char *pid_file;       /* path to the pid file (for reading and writing) */
72 } SilcServerConfigServerInfo;
73
74 typedef struct SilcServerConfigLoggingStruct {
75   char *file;
76   SilcUInt32 maxsize;
77 } SilcServerConfigLogging;
78
79 /* Connection parameters */
80 typedef struct SilcServerConfigConnParams {
81   struct SilcServerConfigConnParams *next;
82   char *name;
83   char *version_protocol;
84   char *version_software;
85   char *version_software_vendor;
86   SilcUInt32 connections_max;
87   SilcUInt32 connections_max_per_host;
88   SilcUInt32 keepalive_secs;
89   SilcUInt32 reconnect_count;
90   SilcUInt32 reconnect_interval;
91   SilcUInt32 reconnect_interval_max;
92   SilcUInt32 key_exchange_rekey;
93   SilcUInt32 qos_rate_limit;
94   SilcUInt32 qos_bytes_limit;
95   SilcUInt32 qos_limit_sec;
96   SilcUInt32 qos_limit_usec;
97   SilcUInt32 chlimit;
98   unsigned int key_exchange_pfs      : 1;
99   unsigned int reconnect_keep_trying : 1;
100   unsigned int anonymous             : 1;
101   unsigned int qos                   : 1;
102 } SilcServerConfigConnParams;
103
104 /* Holds all client authentication data from config file */
105 typedef struct SilcServerConfigClientStruct {
106   char *host;
107   unsigned char *passphrase;
108   SilcUInt32 passphrase_len;
109   SilcBool publickeys;
110   SilcServerConfigConnParams *param;
111   struct SilcServerConfigClientStruct *next;
112 } SilcServerConfigClient;
113
114 /* Holds all server's administrators authentication data from config file */
115 typedef struct SilcServerConfigAdminStruct {
116   char *host;
117   char *user;
118   char *nick;
119   unsigned char *passphrase;
120   SilcUInt32 passphrase_len;
121   SilcBool publickeys;
122   struct SilcServerConfigAdminStruct *next;
123 } SilcServerConfigAdmin;
124
125 /* Holds all configured denied connections from config file */
126 typedef struct SilcServerConfigDenyStruct {
127   char *host;
128   char *reason;
129   struct SilcServerConfigDenyStruct *next;
130 } SilcServerConfigDeny;
131
132 /* Holds all configured server connections from config file */
133 typedef struct SilcServerConfigServerStruct {
134   char *host;
135   unsigned char *passphrase;
136   SilcUInt32 passphrase_len;
137   SilcBool publickeys;
138   SilcServerConfigConnParams *param;
139   SilcBool backup_router;
140   struct SilcServerConfigServerStruct *next;
141 } SilcServerConfigServer;
142
143 /* Holds all configured router connections from config file */
144 typedef struct SilcServerConfigRouterStruct {
145   char *host;
146   unsigned char *passphrase;
147   SilcUInt32 passphrase_len;
148   SilcBool publickeys;
149   SilcUInt16 port;
150   SilcServerConfigConnParams *param;
151   SilcBool initiator;
152   SilcBool backup_router;
153   SilcBool dynamic_connection;
154   char *backup_replace_ip;
155   SilcUInt16 backup_replace_port;
156   SilcBool backup_local;
157   struct SilcServerConfigRouterStruct *next;
158 } SilcServerConfigRouter;
159
160 /* define the SilcServerConfig object */
161 typedef struct {
162   SilcServer server;
163   void *tmp;
164
165   /* Reference count (when this reaches zero, config object is destroyed) */
166   SilcInt32 refcount;
167
168   /* The General section */
169   char *module_path;
170   SilcBool prefer_passphrase_auth;
171   SilcBool require_reverse_lookup;
172   SilcUInt32 channel_rekey_secs;
173   SilcUInt32 key_exchange_timeout;
174   SilcUInt32 conn_auth_timeout;
175   SilcServerConfigConnParams param;
176   SilcBool detach_disabled;
177   SilcUInt32 detach_timeout;
178   SilcBool logging_timestamp;
179   SilcBool logging_quick;
180   long logging_flushdelay;
181   char *debug_string;
182   SilcBool httpd;
183   char *httpd_ip;
184   SilcUInt16 httpd_port;
185   SilcBool dynamic_server;
186   SilcBool local_channels;
187
188   /* Other configuration sections */
189   SilcServerConfigCipher *cipher;
190   SilcServerConfigHash *hash;
191   SilcServerConfigHmac *hmac;
192   SilcServerConfigPkcs *pkcs;
193   SilcServerConfigLogging *logging_info;
194   SilcServerConfigLogging *logging_warnings;
195   SilcServerConfigLogging *logging_errors;
196   SilcServerConfigLogging *logging_fatals;
197   SilcServerConfigServerInfo *server_info;
198   SilcServerConfigConnParams *conn_params;
199   SilcServerConfigClient *clients;
200   SilcServerConfigAdmin *admins;
201   SilcServerConfigDeny *denied;
202   SilcServerConfigServer *servers;
203   SilcServerConfigRouter *routers;
204 } *SilcServerConfig;
205
206 typedef struct {
207   SilcServerConfig config;
208   void *ref_ptr;
209 } SilcServerConfigRef;
210
211 /* Prototypes */
212
213 /* Basic config operations */
214 SilcServerConfig silc_server_config_alloc(const char *filename,
215                                           SilcServer server);
216 void silc_server_config_destroy(SilcServerConfig config);
217 void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
218                             void *ref_ptr);
219 void silc_server_config_unref(SilcServerConfigRef *ref);
220
221 /* Algorithm registering and reset functions */
222 SilcBool silc_server_config_register_ciphers(SilcServer server);
223 SilcBool silc_server_config_register_hashfuncs(SilcServer server);
224 SilcBool silc_server_config_register_hmacs(SilcServer server);
225 SilcBool silc_server_config_register_pkcs(SilcServer server);
226 void silc_server_config_setlogfiles(SilcServer server);
227
228 /* Run-time config access functions */
229 SilcServerConfigClient *
230 silc_server_config_find_client(SilcServer server, char *host);
231 SilcServerConfigAdmin *
232 silc_server_config_find_admin(SilcServer server, char *host, char *user,
233                               char *nick);
234 SilcServerConfigDeny *
235 silc_server_config_find_denied(SilcServer server, char *host);
236 SilcServerConfigServer *
237 silc_server_config_find_server_conn(SilcServer server, char *host);
238 SilcServerConfigRouter *
239 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
240 SilcServerConfigRouter *
241 silc_server_config_find_backup_conn(SilcServer server, char *host);
242 SilcBool silc_server_config_is_primary_route(SilcServer server);
243 SilcServerConfigRouter *
244 silc_server_config_get_primary_router(SilcServer server);
245 SilcServerConfigRouter *
246 silc_server_config_get_backup_router(SilcServer server);
247
248 #endif  /* !SERVERCONFIG_H */