03cb63a0d89b57304e2508dd961e9216d55c0ecb
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Giovanni Giacobbi <giovanni@giacobbi.net>
6
7   Copyright (C) 1997 - 2002 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 typedef struct SilcServerConfigCipherStruct {
25   char *name;
26   char *module;
27   SilcUInt32 key_length;
28   SilcUInt32 block_length;
29   struct SilcServerConfigCipherStruct *next;
30 } SilcServerConfigCipher;
31
32 typedef struct SilcServerConfigHashStruct {
33   char *name;
34   char *module;
35   SilcUInt32 block_length;
36   SilcUInt32 digest_length;
37   struct SilcServerConfigHashStruct *next;
38 } SilcServerConfigHash;
39
40 typedef struct SilcServerConfigHmacStruct {
41   char *name;
42   char *hash;
43   SilcUInt32 mac_length;
44   struct SilcServerConfigHmacStruct *next;
45 } SilcServerConfigHmac;
46
47 typedef struct SilcServerConfigPkcsStruct {
48   char *name;
49   struct SilcServerConfigPkcsStruct *next;
50 } SilcServerConfigPkcs;
51
52 typedef struct SilcServerConfigServerInfoInterfaceStruct {
53   char *server_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   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
179   /* Other configuration sections */
180   SilcServerConfigCipher *cipher;
181   SilcServerConfigHash *hash;
182   SilcServerConfigHmac *hmac;
183   SilcServerConfigPkcs *pkcs;
184   SilcServerConfigLogging *logging_info;
185   SilcServerConfigLogging *logging_warnings;
186   SilcServerConfigLogging *logging_errors;
187   SilcServerConfigLogging *logging_fatals;
188   SilcServerConfigServerInfo *server_info;
189   SilcServerConfigConnParams *conn_params;
190   SilcServerConfigClient *clients;
191   SilcServerConfigAdmin *admins;
192   SilcServerConfigDeny *denied;
193   SilcServerConfigServer *servers;
194   SilcServerConfigRouter *routers;
195 } *SilcServerConfig;
196
197 typedef struct {
198   SilcServerConfig config;
199   void *ref_ptr;
200 } SilcServerConfigRef;
201
202 /* Prototypes */
203
204 /* Basic config operations */
205 SilcServerConfig silc_server_config_alloc(const char *filename);
206 void silc_server_config_destroy(SilcServerConfig config);
207 void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
208                             void *ref_ptr);
209 void silc_server_config_unref(SilcServerConfigRef *ref);
210
211 /* Algorithm registering and reset functions */
212 bool silc_server_config_register_ciphers(SilcServer server);
213 bool silc_server_config_register_hashfuncs(SilcServer server);
214 bool silc_server_config_register_hmacs(SilcServer server);
215 bool silc_server_config_register_pkcs(SilcServer server);
216 void silc_server_config_setlogfiles(SilcServer server);
217
218 /* Run-time config access functions */
219 SilcServerConfigClient *
220 silc_server_config_find_client(SilcServer server, char *host);
221 SilcServerConfigAdmin *
222 silc_server_config_find_admin(SilcServer server, char *host, char *user,
223                               char *nick);
224 SilcServerConfigDeny *
225 silc_server_config_find_denied(SilcServer server, char *host);
226 SilcServerConfigServer *
227 silc_server_config_find_server_conn(SilcServer server, char *host);
228 SilcServerConfigRouter *
229 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
230 SilcServerConfigRouter *
231 silc_server_config_find_backup_conn(SilcServer server, char *host);
232 bool silc_server_config_is_primary_route(SilcServer server);
233 SilcServerConfigRouter *
234 silc_server_config_get_primary_router(SilcServer server);
235 SilcServerConfigRouter *
236 silc_server_config_get_backup_router(SilcServer server);
237
238 #endif  /* !SERVERCONFIG_H */