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 SilcServerConfigSectionCipherStruct {
25   char *name;
26   char *module;
27   uint32 key_length;
28   uint32 block_length;
29   struct SilcServerConfigSectionCipherStruct *next;
30 } SilcServerConfigSectionCipher;
31
32 typedef struct SilcServerConfigSectionHashStruct {
33   char *name;
34   char *module;
35   uint32 block_length;
36   uint32 digest_length;
37   struct SilcServerConfigSectionHashStruct *next;
38 } SilcServerConfigSectionHash;
39
40 typedef struct SilcServerConfigSectionHmacStruct {
41   char *name;
42   char *hash;
43   uint32 mac_length;
44   struct SilcServerConfigSectionHmacStruct *next;
45 } SilcServerConfigSectionHmac;
46
47 typedef struct SilcServerConfigSectionPkcsStruct {
48   char *name;
49   struct SilcServerConfigSectionPkcsStruct *next;
50 } SilcServerConfigSectionPkcs;
51
52 typedef struct SilcServerConfigSectionServerInfoStruct {
53   char *server_name;
54   char *server_ip;
55   uint16 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 } SilcServerConfigSectionServerInfo;
67
68 typedef struct SilcServerConfigSectionLoggingStruct {
69   char *file;
70   uint32 maxsize;
71 } SilcServerConfigSectionLogging;
72
73 /* Connection parameters */
74 typedef struct SilcServerConfigSectionConnectionParam {
75   char *name;
76   uint32 keepalive_secs;
77   uint32 reconnect_count;
78   uint32 reconnect_interval;
79   uint32 reconnect_interval_max;
80   bool reconnect_keep_trying;
81   /* 
82   uint32 connect_freq;
83   uint32 max_links;
84   */
85   struct SilcServerConfigSectionConnectionParam *next;
86 } SilcServerConfigSectionConnectionParam;
87
88 /* Holds all client authentication data from config file */
89 typedef struct SilcServerConfigSectionClientStruct {
90   char *host;
91   unsigned char *passphrase;
92   uint32 passphrase_len;
93   void *publickey;
94   uint16 port;
95   char *param_name;
96   SilcServerConfigSectionConnectionParam *param;
97   struct SilcServerConfigSectionClientStruct *next;
98 } SilcServerConfigSectionClient;
99
100 /* Holds all server's administrators authentication data from config file */
101 typedef struct SilcServerConfigSectionAdminStruct {
102   char *host;
103   char *user;
104   char *nick;
105   unsigned char *passphrase;
106   uint32 passphrase_len;
107   void *publickey;
108   struct SilcServerConfigSectionAdminStruct *next;
109 } SilcServerConfigSectionAdmin;
110
111 /* Holds all configured denied connections from config file */
112 typedef struct SilcServerConfigSectionDenyStruct {
113   char *host;
114   uint16 port;
115   char *reason;
116   struct SilcServerConfigSectionDenyStruct *next;
117 } SilcServerConfigSectionDeny;
118
119 /* Holds all configured server connections from config file */
120 typedef struct SilcServerConfigSectionServerStruct {
121   char *host;
122   unsigned char *passphrase;
123   uint32 passphrase_len;
124   void *publickey;
125   char *version;
126   char *param_name;
127   SilcServerConfigSectionConnectionParam *param;
128   bool backup_router;
129   struct SilcServerConfigSectionServerStruct *next;
130 } SilcServerConfigSectionServer;
131
132 /* Holds all configured router connections from config file */
133 typedef struct SilcServerConfigSectionRouterStruct {
134   char *host;
135   unsigned char *passphrase;
136   uint32 passphrase_len;
137   void *publickey;
138   uint16 port;
139   char *version;
140   char *param_name;
141   SilcServerConfigSectionConnectionParam *param;
142   bool initiator;
143   bool backup_router;
144   char *backup_replace_ip;
145   uint16 backup_replace_port;
146   bool backup_local;
147   struct SilcServerConfigSectionRouterStruct *next;
148 } SilcServerConfigSectionRouter;
149
150 /* define the SilcServerConfig object */
151 typedef struct {
152   void *tmp;
153
154   /* The General section */
155   char *module_path;
156   bool prefer_passphrase_auth;
157   bool require_reverse_lookup;
158   /* XXX Still think whether to actually have params in general... -Pekka */
159   SilcServerConfigSectionConnectionParam param;
160
161   /* Other configuration sections */
162   SilcServerConfigSectionCipher *cipher;
163   SilcServerConfigSectionHash *hash;
164   SilcServerConfigSectionHmac *hmac;
165   SilcServerConfigSectionPkcs *pkcs;
166   SilcServerConfigSectionLogging *logging_info;
167   SilcServerConfigSectionLogging *logging_warnings;
168   SilcServerConfigSectionLogging *logging_errors;
169   SilcServerConfigSectionLogging *logging_fatals;
170   SilcServerConfigSectionServerInfo *server_info;
171   SilcServerConfigSectionConnectionParam *conn_params;
172   SilcServerConfigSectionClient *clients;
173   SilcServerConfigSectionAdmin *admins;
174   SilcServerConfigSectionDeny *denied;
175   SilcServerConfigSectionServer *servers;
176   SilcServerConfigSectionRouter *routers;
177 } *SilcServerConfig;
178
179 /* Prototypes */
180
181 /* Basic config operations */
182 SilcServerConfig silc_server_config_alloc(char *filename);
183 void silc_server_config_destroy(SilcServerConfig config);
184
185 /* Algorithm registering and reset functions */
186 bool silc_server_config_register_ciphers(SilcServer server);
187 bool silc_server_config_register_hashfuncs(SilcServer server);
188 bool silc_server_config_register_hmacs(SilcServer server);
189 bool silc_server_config_register_pkcs(SilcServer server);
190 void silc_server_config_setlogfiles(SilcServer server);
191
192 /* Run-time config access functions */
193 SilcServerConfigSectionClient *
194 silc_server_config_find_client(SilcServer server, char *host, int port);
195 SilcServerConfigSectionAdmin *
196 silc_server_config_find_admin(SilcServer server, char *host, char *user, 
197                               char *nick);
198 SilcServerConfigSectionDeny *
199 silc_server_config_find_denied(SilcServer server, char *host, uint16 port);
200 SilcServerConfigSectionServer *
201 silc_server_config_find_server_conn(SilcServer server, char *host);
202 SilcServerConfigSectionRouter *
203 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
204 bool silc_server_config_is_primary_route(SilcServer server);
205 SilcServerConfigSectionRouter *
206 silc_server_config_get_primary_router(SilcServer server);
207 bool silc_server_config_set_defaults(SilcServer server);
208
209 #endif  /* !SERVERCONFIG_H */