Added anonymous client connections support.
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Johnny Mnemonic <johnny@themnemonic.org>
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   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   bool key_exchange_pfs;
93   bool reconnect_keep_trying;
94   bool anonymous;
95   struct SilcServerConfigConnParams *next;
96 } SilcServerConfigConnParams;
97
98 /* Holds all client authentication data from config file */
99 typedef struct SilcServerConfigClientStruct {
100   char *host;
101   unsigned char *passphrase;
102   SilcUInt32 passphrase_len;
103   SilcHashTable publickeys;
104   SilcServerConfigConnParams *param;
105   struct SilcServerConfigClientStruct *next;
106 } SilcServerConfigClient;
107
108 /* Holds all server's administrators authentication data from config file */
109 typedef struct SilcServerConfigAdminStruct {
110   char *host;
111   char *user;
112   char *nick;
113   unsigned char *passphrase;
114   SilcUInt32 passphrase_len;
115   SilcHashTable publickeys;
116   struct SilcServerConfigAdminStruct *next;
117 } SilcServerConfigAdmin;
118
119 /* Holds all configured denied connections from config file */
120 typedef struct SilcServerConfigDenyStruct {
121   char *host;
122   char *reason;
123   struct SilcServerConfigDenyStruct *next;
124 } SilcServerConfigDeny;
125
126 /* Holds all configured server connections from config file */
127 typedef struct SilcServerConfigServerStruct {
128   char *host;
129   unsigned char *passphrase;
130   SilcUInt32 passphrase_len;
131   SilcHashTable publickeys;
132   SilcServerConfigConnParams *param;
133   bool backup_router;
134   struct SilcServerConfigServerStruct *next;
135 } SilcServerConfigServer;
136
137 /* Holds all configured router connections from config file */
138 typedef struct SilcServerConfigRouterStruct {
139   char *host;
140   unsigned char *passphrase;
141   SilcUInt32 passphrase_len;
142   SilcHashTable publickeys;
143   SilcUInt16 port;
144   SilcServerConfigConnParams *param;
145   bool initiator;
146   bool backup_router;
147   char *backup_replace_ip;
148   SilcUInt16 backup_replace_port;
149   bool backup_local;
150   struct SilcServerConfigRouterStruct *next;
151 } SilcServerConfigRouter;
152
153 /* define the SilcServerConfig object */
154 typedef struct {
155   void *tmp;
156
157   /* Reference count (when this reaches zero, config object is destroyed) */
158   SilcInt32 refcount;
159
160   /* The General section */
161   char *module_path;
162   bool prefer_passphrase_auth;
163   bool require_reverse_lookup;
164   SilcUInt32 channel_rekey_secs;
165   SilcUInt32 key_exchange_timeout;
166   SilcUInt32 conn_auth_timeout;
167   SilcServerConfigConnParams param;
168   bool detach_disabled;
169   SilcUInt32 detach_timeout;
170   bool logging_timestamp;
171   bool logging_quick;
172   long logging_flushdelay;
173
174   /* Other configuration sections */
175   SilcServerConfigCipher *cipher;
176   SilcServerConfigHash *hash;
177   SilcServerConfigHmac *hmac;
178   SilcServerConfigPkcs *pkcs;
179   SilcServerConfigLogging *logging_info;
180   SilcServerConfigLogging *logging_warnings;
181   SilcServerConfigLogging *logging_errors;
182   SilcServerConfigLogging *logging_fatals;
183   SilcServerConfigServerInfo *server_info;
184   SilcServerConfigConnParams *conn_params;
185   SilcServerConfigClient *clients;
186   SilcServerConfigAdmin *admins;
187   SilcServerConfigDeny *denied;
188   SilcServerConfigServer *servers;
189   SilcServerConfigRouter *routers;
190 } *SilcServerConfig;
191
192 typedef struct {
193   SilcServerConfig config;
194   void *ref_ptr;
195 } SilcServerConfigRef;
196
197 /* Prototypes */
198
199 /* Basic config operations */
200 SilcServerConfig silc_server_config_alloc(const char *filename);
201 void silc_server_config_destroy(SilcServerConfig config);
202 void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
203                             void *ref_ptr);
204 void silc_server_config_unref(SilcServerConfigRef *ref);
205
206 /* Algorithm registering and reset functions */
207 bool silc_server_config_register_ciphers(SilcServer server);
208 bool silc_server_config_register_hashfuncs(SilcServer server);
209 bool silc_server_config_register_hmacs(SilcServer server);
210 bool silc_server_config_register_pkcs(SilcServer server);
211 void silc_server_config_setlogfiles(SilcServer server);
212
213 /* Run-time config access functions */
214 SilcServerConfigClient *
215 silc_server_config_find_client(SilcServer server, char *host);
216 SilcServerConfigAdmin *
217 silc_server_config_find_admin(SilcServer server, char *host, char *user,
218                               char *nick);
219 SilcServerConfigDeny *
220 silc_server_config_find_denied(SilcServer server, char *host);
221 SilcServerConfigServer *
222 silc_server_config_find_server_conn(SilcServer server, char *host);
223 SilcServerConfigRouter *
224 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
225 SilcServerConfigRouter *
226 silc_server_config_find_backup_conn(SilcServer server, char *host);
227 bool silc_server_config_is_primary_route(SilcServer server);
228 SilcServerConfigRouter *
229 silc_server_config_get_primary_router(SilcServer server);
230 SilcServerConfigRouter *
231 silc_server_config_get_backup_router(SilcServer server);
232
233 #endif  /* !SERVERCONFIG_H */