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