updates.
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 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 /* Holds information of configured algorithms */
25 typedef struct SilcServerConfigSectionAlgStruct {
26   char *alg_name;
27   char *sim_name;
28   unsigned int block_len;
29   unsigned int key_len;
30   struct SilcServerConfigSectionAlgStruct *next;
31   struct SilcServerConfigSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcServerConfigSectionAlg;
34
35 /* Holds server information from config file */
36 typedef struct {
37   char *server_name;
38   char *server_ip;
39   char *location;
40   unsigned short port;
41 } SilcServerConfigSectionServerInfo;
42
43 /* Holds server's administrative information from config file */
44 typedef struct {
45   char *location;
46   char *server_type;
47   char *admin_name;
48   char *admin_email;
49 } SilcServerConfigSectionAdminInfo;
50
51 /* Holds all the ports the server is listenning on */
52 typedef struct SilcServerConfigSectionListenPortStruct {
53   char *host;
54   char *remote_ip;
55   unsigned short port;
56   struct SilcServerConfigSectionListenPortStruct *next;
57   struct SilcServerConfigSectionListenPortStruct *prev;
58 } SilcServerConfigSectionListenPort;
59
60 /* Holds server's execution identity, or the user and group which
61    to change from root when server starts */
62 typedef struct {
63  char *user;
64  char *group;
65 } SilcServerConfigSectionIdentity;
66
67 /* Holds all the configured log files. */
68 typedef struct SilcServerConfigSectionLoggingStruct {
69   char *logtype;
70   char *filename;
71   unsigned int maxsize;
72   struct SilcServerConfigSectionLoggingStruct *next;
73   struct SilcServerConfigSectionLoggingStruct *prev;
74
75 /* Allowed <Logging> section types */
76 #define SILC_CONFIG_SERVER_LF_INFO "infologfile"
77 #define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile"
78 #define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile"
79 #define SILC_CONFIG_SERVER_LF_FATAL "fatalogfile"
80 } SilcServerConfigSectionLogging;
81
82 /* Holds all configured connection classes */
83 typedef struct SilcServerConfigSectionConnectionClassStruct {
84   unsigned int class;
85   unsigned int ping_freq;
86   unsigned int connect_freq;
87   unsigned int max_links;
88   struct SilcServerConfigSectionConnectionClassStruct *next;
89   struct SilcServerConfigSectionConnectionClassStruct *prev;
90 } SilcServerConfigSectionConnectionClass;
91
92 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
93 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
94
95 /* Holds all client authentication data from config file */
96 typedef struct SilcServerConfigSectionClientConnectionStruct {
97   char *host;
98   int auth_meth;
99   char *auth_data;
100   unsigned short port;
101   unsigned int class;
102   struct SilcServerConfigSectionClientConnectionStruct *next;
103   struct SilcServerConfigSectionClientConnectionStruct *prev;
104 } SilcServerConfigSectionClientConnection;
105
106 /* Hols all server's administrators authentication data from config file */
107 typedef struct SilcServerConfigSectionAdminConnectionStruct {
108   char *host;
109   int auth_meth;
110   char *auth_data;
111   char *nickname;
112   unsigned int class;
113   struct SilcServerConfigSectionAdminConnectionStruct *next;
114   struct SilcServerConfigSectionAdminConnectionStruct *prev;
115 } SilcServerConfigSectionAdminConnection;
116
117 /* Holds all configured server/router connections from config file */
118 typedef struct SilcServerConfigSectionServerConnectionStruct {
119   char *host;
120   int auth_meth;
121   char *auth_data;
122   unsigned short port;
123   char *version;
124   unsigned int class;
125   int initiator;
126   struct SilcServerConfigSectionServerConnectionStruct *next;
127   struct SilcServerConfigSectionServerConnectionStruct *prev;
128 } SilcServerConfigSectionServerConnection;
129
130 /* Holds all configured denied connections from config file */
131 typedef struct {
132   char *host;
133   char *time;
134   char *comment;
135   unsigned short port;
136 } SilcServerConfigSectionDenyConnection;
137
138 /* Holds all client redirections from config file */
139 typedef struct {
140   char *host;
141   unsigned short port;
142 } SilcServerConfigSectionRedirectClient;
143
144 /* Holds motd file */
145 typedef struct {
146   char *motd_file;
147 } SilcServerConfigSectionMotd;
148
149 /* 
150    SILC Server Config object. 
151
152    This object holds all the data parsed from the SILC server configuration
153    file. This is mainly used at the initialization of the server.
154
155 */
156 typedef struct {
157   /* Pointer back to the server */
158   void *server;
159
160   /* Filename of the configuration file */
161   char *filename;
162
163   /* Configuration sections */
164   SilcServerConfigSectionAlg *cipher;
165   SilcServerConfigSectionAlg *pkcs;
166   SilcServerConfigSectionAlg *hash_func;
167   SilcServerConfigSectionAlg *hmac;
168   SilcServerConfigSectionServerInfo *server_info;
169   SilcServerConfigSectionAdminInfo *admin_info;
170   SilcServerConfigSectionListenPort *listen_port;
171   SilcServerConfigSectionIdentity *identity;
172   SilcServerConfigSectionLogging *logging;
173   SilcServerConfigSectionConnectionClass *conn_class;
174   SilcServerConfigSectionClientConnection *clients;
175   SilcServerConfigSectionServerConnection *servers;
176   SilcServerConfigSectionServerConnection *routers;
177   SilcServerConfigSectionAdminConnection *admins;
178   SilcServerConfigSectionDenyConnection *denied;
179   SilcServerConfigSectionRedirectClient *redirect;
180   SilcServerConfigSectionMotd *motd;
181 } SilcServerConfigObject;
182
183 typedef SilcServerConfigObject *SilcServerConfig;
184
185 /* Configuration section type enumerations. */
186 typedef enum {
187   SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
188   SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
189   SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
190   SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
191   SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
192   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
193   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
194   SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
195   SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
196   SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
197   SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
198   SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
199   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
200   SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
201   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
202   SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
203   SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT,
204   SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
205 } SilcServerConfigSectionType;
206
207 /* SILC Configuration Section structure. */
208 typedef struct {
209   const char *section;
210   SilcServerConfigSectionType type;
211   unsigned int maxfields;
212 } SilcServerConfigSection;
213
214 /* LIst of all possible config sections in SILC server. */
215 extern SilcServerConfigSection silc_server_config_sections[];
216
217 /* Structure used in parsing the configuration lines. The line is read
218    from a file to this structure before parsing it further. */
219 typedef struct SilcServerConfigParseStruct {
220   SilcBuffer line;
221   unsigned int linenum;
222   SilcServerConfigSection *section;
223   struct SilcServerConfigParseStruct *next;
224   struct SilcServerConfigParseStruct *prev;
225 } *SilcServerConfigParse;
226
227 /* Macros */
228
229 /* Allocates list entries for configuration sections. Used by all
230    config sections as this is common. */
231 #define SILC_SERVER_CONFIG_LIST_ALLOC(x)                \
232 do {                                                    \
233   if (!(x)) {                                           \
234     (x) = silc_calloc(1, sizeof(*(x)));                 \
235     (x)->next = NULL;                                   \
236     (x)->prev = NULL;                                   \
237   } else {                                              \
238     if (!(x)->next) {                                   \
239       (x)->next = silc_calloc(1, sizeof(*(x)->next));   \
240       (x)->next->next = NULL;                           \
241       (x)->next->prev = (x);                            \
242       (x) = (x)->next;                                  \
243     }                                                   \
244   }                                                     \
245 } while(0)
246
247 /* Prototypes */
248 SilcServerConfig silc_server_config_alloc(char *filename);
249 void silc_server_config_free(SilcServerConfig config);
250 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
251                              SilcServerConfigParse *return_config);
252 int silc_server_config_parse_lines(SilcServerConfig config, 
253                                    SilcServerConfigParse parse_config);
254 int silc_server_config_check_sections(unsigned int checkmask);
255 void silc_server_config_setlogfiles(SilcServerConfig config);
256 void silc_server_config_register_ciphers(SilcServerConfig config);
257 void silc_server_config_register_pkcs(SilcServerConfig config);
258 void silc_server_config_register_hashfuncs(SilcServerConfig config);
259 void silc_server_config_register_hmacs(SilcServerConfig config);
260 SilcServerConfigSectionClientConnection *
261 silc_server_config_find_client_conn(SilcServerConfig config, 
262                                     char *host, int port);
263 SilcServerConfigSectionServerConnection *
264 silc_server_config_find_server_conn(SilcServerConfig config, 
265                                     char *host, int port);
266 SilcServerConfigSectionServerConnection *
267 silc_server_config_find_router_conn(SilcServerConfig config, 
268                                     char *host, int port);
269 void silc_server_config_print();
270
271 #endif