2ec5f8a33837f06b6bb1b22045e8b5bc038d4f20
[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   SilcServerConfigSectionConnectionParam *param;
96   struct SilcServerConfigSectionClientStruct *next;
97 } SilcServerConfigSectionClient;
98
99 /* Holds all server's administrators authentication data from config file */
100 typedef struct SilcServerConfigSectionAdminStruct {
101   char *host;
102   char *user;
103   char *nick;
104   unsigned char *passphrase;
105   uint32 passphrase_len;
106   void *publickey;
107   struct SilcServerConfigSectionAdminStruct *next;
108 } SilcServerConfigSectionAdmin;
109
110 /* Holds all configured denied connections from config file */
111 typedef struct SilcServerConfigSectionDenyStruct {
112   char *host;
113   uint16 port;
114   char *reason;
115   struct SilcServerConfigSectionDenyStruct *next;
116 } SilcServerConfigSectionDeny;
117
118 /* Holds all configured server connections from config file */
119 typedef struct SilcServerConfigSectionServerStruct {
120   char *host;
121   unsigned char *passphrase;
122   uint32 passphrase_len;
123   void *publickey;
124   char *version;
125   SilcServerConfigSectionConnectionParam *param;
126   bool backup_router;
127   struct SilcServerConfigSectionServerStruct *next;
128 } SilcServerConfigSectionServer;
129
130 /* Holds all configured router connections from config file */
131 typedef struct SilcServerConfigSectionRouterStruct {
132   char *host;
133   unsigned char *passphrase;
134   uint32 passphrase_len;
135   void *publickey;
136   uint16 port;
137   char *version;
138   SilcServerConfigSectionConnectionParam *param;
139   bool initiator;
140   bool backup_router;
141   char *backup_replace_ip;
142   uint16 backup_replace_port;
143   bool backup_local;
144   struct SilcServerConfigSectionRouterStruct *next;
145 } SilcServerConfigSectionRouter;
146
147 /* define the SilcServerConfig object */
148 typedef struct {
149   void *tmp;
150
151   /* The General section */
152   char *module_path;
153   bool prefer_passphrase_auth;
154   bool require_reverse_lookup;
155   /* XXX Still think whether to actually have params in general... -Pekka */
156   SilcServerConfigSectionConnectionParam param;
157
158   /* Other configuration sections */
159   SilcServerConfigSectionCipher *cipher;
160   SilcServerConfigSectionHash *hash;
161   SilcServerConfigSectionHmac *hmac;
162   SilcServerConfigSectionPkcs *pkcs;
163   SilcServerConfigSectionLogging *logging_info;
164   SilcServerConfigSectionLogging *logging_warnings;
165   SilcServerConfigSectionLogging *logging_errors;
166   SilcServerConfigSectionLogging *logging_fatals;
167   SilcServerConfigSectionServerInfo *server_info;
168   SilcServerConfigSectionConnectionParam *conn_params;
169   SilcServerConfigSectionClient *clients;
170   SilcServerConfigSectionAdmin *admins;
171   SilcServerConfigSectionDeny *denied;
172   SilcServerConfigSectionServer *servers;
173   SilcServerConfigSectionRouter *routers;
174 } *SilcServerConfig;
175
176 /* Prototypes */
177
178 /* Basic config operations */
179 SilcServerConfig silc_server_config_alloc(char *filename);
180 void silc_server_config_destroy(SilcServerConfig config);
181
182 /* Algorithm registering and reset functions */
183 bool silc_server_config_register_ciphers(SilcServer server);
184 bool silc_server_config_register_hashfuncs(SilcServer server);
185 bool silc_server_config_register_hmacs(SilcServer server);
186 bool silc_server_config_register_pkcs(SilcServer server);
187 void silc_server_config_setlogfiles(SilcServer server);
188
189 /* Run-time config access functions */
190 SilcServerConfigSectionClient *
191 silc_server_config_find_client(SilcServer server, char *host, int port);
192 SilcServerConfigSectionAdmin *
193 silc_server_config_find_admin(SilcServer server, char *host, char *user, 
194                               char *nick);
195 SilcServerConfigSectionDeny *
196 silc_server_config_find_denied(SilcServer server, char *host, uint16 port);
197 SilcServerConfigSectionServer *
198 silc_server_config_find_server_conn(SilcServer server, char *host);
199 SilcServerConfigSectionRouter *
200 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
201 bool silc_server_config_is_primary_route(SilcServer server);
202 SilcServerConfigSectionRouter *
203 silc_server_config_get_primary_router(SilcServer server);
204 bool silc_server_config_set_defaults(SilcServer server);
205
206 #endif  /* !SERVERCONFIG_H */