Merged silc_1_0_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 - 2005 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   SilcUInt16 port;
54   struct SilcServerConfigServerInfoInterfaceStruct *next;
55 } SilcServerConfigServerInfoInterface;
56
57 typedef struct SilcServerConfigServerInfoStruct {
58   char *server_name;
59   SilcServerConfigServerInfoInterface *primary;
60   SilcServerConfigServerInfoInterface *secondary;
61   char *server_type;    /* E.g. "Test Server" */
62   char *location;       /* geographic location */
63   char *admin;          /* admin full name */
64   char *email;          /* admin's email address */
65   char *user;           /* userid the server should be runned at */
66   char *group;          /* ditto, but about groupid */
67   SilcPublicKey public_key;
68   SilcPrivateKey private_key;
69   char *motd_file;      /* path to text motd file (reading only) */
70   char *pid_file;       /* path to the pid file (for reading and writing) */
71 } SilcServerConfigServerInfo;
72
73 typedef struct SilcServerConfigLoggingStruct {
74   char *file;
75   SilcUInt32 maxsize;
76 } SilcServerConfigLogging;
77
78 /* Connection parameters */
79 typedef struct SilcServerConfigConnParams {
80   struct SilcServerConfigConnParams *next;
81   char *name;
82   char *version_protocol;
83   char *version_software;
84   char *version_software_vendor;
85   SilcUInt32 connections_max;
86   SilcUInt32 connections_max_per_host;
87   SilcUInt32 keepalive_secs;
88   SilcUInt32 reconnect_count;
89   SilcUInt32 reconnect_interval;
90   SilcUInt32 reconnect_interval_max;
91   SilcUInt32 key_exchange_rekey;
92   SilcUInt32 qos_rate_limit;
93   SilcUInt32 qos_bytes_limit;
94   SilcUInt32 qos_limit_sec;
95   SilcUInt32 qos_limit_usec;
96   SilcUInt32 chlimit;
97   unsigned int key_exchange_pfs      : 1;
98   unsigned int reconnect_keep_trying : 1;
99   unsigned int anonymous             : 1;
100   unsigned int qos                   : 1;
101 } SilcServerConfigConnParams;
102
103 /* Holds all client authentication data from config file */
104 typedef struct SilcServerConfigClientStruct {
105   char *host;
106   unsigned char *passphrase;
107   SilcUInt32 passphrase_len;
108   SilcHashTable publickeys;
109   SilcServerConfigConnParams *param;
110   struct SilcServerConfigClientStruct *next;
111 } SilcServerConfigClient;
112
113 /* Holds all server's administrators authentication data from config file */
114 typedef struct SilcServerConfigAdminStruct {
115   char *host;
116   char *user;
117   char *nick;
118   unsigned char *passphrase;
119   SilcUInt32 passphrase_len;
120   SilcHashTable publickeys;
121   struct SilcServerConfigAdminStruct *next;
122 } SilcServerConfigAdmin;
123
124 /* Holds all configured denied connections from config file */
125 typedef struct SilcServerConfigDenyStruct {
126   char *host;
127   char *reason;
128   struct SilcServerConfigDenyStruct *next;
129 } SilcServerConfigDeny;
130
131 /* Holds all configured server connections from config file */
132 typedef struct SilcServerConfigServerStruct {
133   char *host;
134   unsigned char *passphrase;
135   SilcUInt32 passphrase_len;
136   SilcHashTable publickeys;
137   SilcServerConfigConnParams *param;
138   bool backup_router;
139   struct SilcServerConfigServerStruct *next;
140 } SilcServerConfigServer;
141
142 /* Holds all configured router connections from config file */
143 typedef struct SilcServerConfigRouterStruct {
144   char *host;
145   unsigned char *passphrase;
146   SilcUInt32 passphrase_len;
147   SilcHashTable publickeys;
148   SilcUInt16 port;
149   SilcServerConfigConnParams *param;
150   bool initiator;
151   bool backup_router;
152   char *backup_replace_ip;
153   SilcUInt16 backup_replace_port;
154   bool backup_local;
155   struct SilcServerConfigRouterStruct *next;
156 } SilcServerConfigRouter;
157
158 /* define the SilcServerConfig object */
159 typedef struct {
160   void *tmp;
161
162   /* Reference count (when this reaches zero, config object is destroyed) */
163   SilcInt32 refcount;
164
165   /* The General section */
166   char *module_path;
167   bool prefer_passphrase_auth;
168   bool require_reverse_lookup;
169   SilcUInt32 channel_rekey_secs;
170   SilcUInt32 key_exchange_timeout;
171   SilcUInt32 conn_auth_timeout;
172   SilcServerConfigConnParams param;
173   bool detach_disabled;
174   SilcUInt32 detach_timeout;
175   bool logging_timestamp;
176   bool logging_quick;
177   long logging_flushdelay;
178   char *debug_string;
179
180   /* Other configuration sections */
181   SilcServerConfigCipher *cipher;
182   SilcServerConfigHash *hash;
183   SilcServerConfigHmac *hmac;
184   SilcServerConfigPkcs *pkcs;
185   SilcServerConfigLogging *logging_info;
186   SilcServerConfigLogging *logging_warnings;
187   SilcServerConfigLogging *logging_errors;
188   SilcServerConfigLogging *logging_fatals;
189   SilcServerConfigServerInfo *server_info;
190   SilcServerConfigConnParams *conn_params;
191   SilcServerConfigClient *clients;
192   SilcServerConfigAdmin *admins;
193   SilcServerConfigDeny *denied;
194   SilcServerConfigServer *servers;
195   SilcServerConfigRouter *routers;
196 } *SilcServerConfig;
197
198 typedef struct {
199   SilcServerConfig config;
200   void *ref_ptr;
201 } SilcServerConfigRef;
202
203 /* Prototypes */
204
205 /* Basic config operations */
206 SilcServerConfig silc_server_config_alloc(const char *filename);
207 void silc_server_config_destroy(SilcServerConfig config);
208 void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
209                             void *ref_ptr);
210 void silc_server_config_unref(SilcServerConfigRef *ref);
211
212 /* Algorithm registering and reset functions */
213 bool silc_server_config_register_ciphers(SilcServer server);
214 bool silc_server_config_register_hashfuncs(SilcServer server);
215 bool silc_server_config_register_hmacs(SilcServer server);
216 bool silc_server_config_register_pkcs(SilcServer server);
217 void silc_server_config_setlogfiles(SilcServer server);
218
219 /* Run-time config access functions */
220 SilcServerConfigClient *
221 silc_server_config_find_client(SilcServer server, char *host);
222 SilcServerConfigAdmin *
223 silc_server_config_find_admin(SilcServer server, char *host, char *user,
224                               char *nick);
225 SilcServerConfigDeny *
226 silc_server_config_find_denied(SilcServer server, char *host);
227 SilcServerConfigServer *
228 silc_server_config_find_server_conn(SilcServer server, char *host);
229 SilcServerConfigRouter *
230 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
231 SilcServerConfigRouter *
232 silc_server_config_find_backup_conn(SilcServer server, char *host);
233 bool silc_server_config_is_primary_route(SilcServer server);
234 SilcServerConfigRouter *
235 silc_server_config_get_primary_router(SilcServer server);
236 SilcServerConfigRouter *
237 silc_server_config_get_backup_router(SilcServer server);
238
239 #endif  /* !SERVERCONFIG_H */