updates. New data types.
[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   uint32 block_len;
29   uint32 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   uint16 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   uint16 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   uint32 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   uint32 class;
85   uint32 ping_freq;
86   uint32 connect_freq;
87   uint32 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   SilcAuthMethod auth_meth;
99   void *auth_data;
100   uint32 auth_data_len;
101   uint16 port;
102   uint32 class;
103   struct SilcServerConfigSectionClientConnectionStruct *next;
104   struct SilcServerConfigSectionClientConnectionStruct *prev;
105 } SilcServerConfigSectionClientConnection;
106
107 /* Hols all server's administrators authentication data from config file */
108 typedef struct SilcServerConfigSectionAdminConnectionStruct {
109   char *host;
110   char *username;
111   char *nickname;
112   SilcAuthMethod auth_meth;
113   void *auth_data;
114   uint32 auth_data_len;
115   struct SilcServerConfigSectionAdminConnectionStruct *next;
116   struct SilcServerConfigSectionAdminConnectionStruct *prev;
117 } SilcServerConfigSectionAdminConnection;
118
119 /* Holds all configured server/router connections from config file */
120 typedef struct SilcServerConfigSectionServerConnectionStruct {
121   char *host;
122   SilcAuthMethod auth_meth;
123   void *auth_data;
124   uint32 auth_data_len;
125   uint16 port;
126   char *version;
127   uint32 class;
128   int initiator;
129   struct SilcServerConfigSectionServerConnectionStruct *next;
130   struct SilcServerConfigSectionServerConnectionStruct *prev;
131 } SilcServerConfigSectionServerConnection;
132
133 /* Holds all configured denied connections from config file */
134 typedef struct {
135   char *host;
136   char *time;
137   char *comment;
138   uint16 port;
139 } SilcServerConfigSectionDenyConnection;
140
141 /* Holds motd file */
142 typedef struct {
143   char *motd_file;
144 } SilcServerConfigSectionMotd;
145
146 /* 
147    SILC Server Config object. 
148
149    This object holds all the data parsed from the SILC server configuration
150    file. This is mainly used at the initialization of the server.
151
152 */
153 typedef struct {
154   /* Pointer back to the server */
155   void *server;
156
157   /* Filename of the configuration file */
158   char *filename;
159
160   /* Configuration sections */
161   SilcServerConfigSectionAlg *cipher;
162   SilcServerConfigSectionAlg *pkcs;
163   SilcServerConfigSectionAlg *hash_func;
164   SilcServerConfigSectionAlg *hmac;
165   SilcServerConfigSectionServerInfo *server_info;
166   SilcServerConfigSectionAdminInfo *admin_info;
167   SilcServerConfigSectionListenPort *listen_port;
168   SilcServerConfigSectionIdentity *identity;
169   SilcServerConfigSectionLogging *logging;
170   SilcServerConfigSectionConnectionClass *conn_class;
171   SilcServerConfigSectionClientConnection *clients;
172   SilcServerConfigSectionServerConnection *servers;
173   SilcServerConfigSectionServerConnection *routers;
174   SilcServerConfigSectionAdminConnection *admins;
175   SilcServerConfigSectionDenyConnection *denied;
176   SilcServerConfigSectionMotd *motd;
177 } SilcServerConfigObject;
178
179 typedef SilcServerConfigObject *SilcServerConfig;
180
181 /* Configuration section type enumerations. */
182 typedef enum {
183   SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
184   SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
185   SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
186   SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
187   SILC_CONFIG_SERVER_SECTION_TYPE_HMAC,
188   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
189   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
190   SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
191   SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY,
192   SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
193   SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
194   SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
195   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
196   SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
197   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
198   SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
199   SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
200 } SilcServerConfigSectionType;
201
202 /* SILC Configuration Section structure. */
203 typedef struct {
204   const char *section;
205   SilcServerConfigSectionType type;
206   int maxfields;
207 } SilcServerConfigSection;
208
209 /* LIst of all possible config sections in SILC server. */
210 extern SilcServerConfigSection silc_server_config_sections[];
211
212 /* Structure used in parsing the configuration lines. The line is read
213    from a file to this structure before parsing it further. */
214 typedef struct SilcServerConfigParseStruct {
215   SilcBuffer line;
216   int linenum;
217   SilcServerConfigSection *section;
218   struct SilcServerConfigParseStruct *next;
219   struct SilcServerConfigParseStruct *prev;
220 } *SilcServerConfigParse;
221
222 /* Macros */
223
224 /* Allocates list entries for configuration sections. Used by all
225    config sections as this is common. */
226 #define SILC_SERVER_CONFIG_LIST_ALLOC(x)                \
227 do {                                                    \
228   if (!(x)) {                                           \
229     (x) = silc_calloc(1, sizeof(*(x)));                 \
230     (x)->next = NULL;                                   \
231     (x)->prev = NULL;                                   \
232   } else {                                              \
233     if (!(x)->next) {                                   \
234       (x)->next = silc_calloc(1, sizeof(*(x)->next));   \
235       (x)->next->next = NULL;                           \
236       (x)->next->prev = (x);                            \
237       (x) = (x)->next;                                  \
238     }                                                   \
239   }                                                     \
240 } while(0)
241
242 /* Prototypes */
243 SilcServerConfig silc_server_config_alloc(char *filename);
244 void silc_server_config_free(SilcServerConfig config);
245 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer,
246                              SilcServerConfigParse *return_config);
247 int silc_server_config_parse_lines(SilcServerConfig config, 
248                                    SilcServerConfigParse parse_config);
249 int silc_server_config_check_sections(uint32 checkmask);
250 void silc_server_config_setlogfiles(SilcServerConfig config);
251 void silc_server_config_register_ciphers(SilcServerConfig config);
252 void silc_server_config_register_pkcs(SilcServerConfig config);
253 void silc_server_config_register_hashfuncs(SilcServerConfig config);
254 void silc_server_config_register_hmacs(SilcServerConfig config);
255 SilcServerConfigSectionClientConnection *
256 silc_server_config_find_client_conn(SilcServerConfig config, 
257                                     char *host, int port);
258 SilcServerConfigSectionServerConnection *
259 silc_server_config_find_server_conn(SilcServerConfig config, 
260                                     char *host, int port);
261 SilcServerConfigSectionServerConnection *
262 silc_server_config_find_router_conn(SilcServerConfig config, 
263                                     char *host, int port);
264 SilcServerConfigSectionAdminConnection *
265 silc_server_config_find_admin(SilcServerConfig config,
266                               char *host, char *username, char *nickname);
267 void silc_server_config_print();
268
269 #endif