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