Initial revision
[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 SilcConfigServerSectionAlgStruct {
26   char *alg_name;
27   char *sim_name;
28   unsigned int block_len;
29   unsigned int key_len;
30   struct SilcConfigServerSectionAlgStruct *next;
31   struct SilcConfigServerSectionAlgStruct *prev;
32 #define SILC_CONFIG_SERVER_MODNAME "builtin"
33 } SilcConfigServerSectionAlg;
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 } SilcConfigServerSectionServerInfo;
42
43 /* Holds server's administrative information from config file */
44 typedef struct {
45   char *server_type;
46   char *admin_name;
47   char *admin_email;
48 } SilcConfigServerSectionAdminInfo;
49
50 /* Holds all the ports the server is listenning on */
51 typedef struct SilcConfigServerSectionListenPortStruct {
52   char *host;
53   char *remote_ip;
54   unsigned short port;
55   struct SilcConfigServerSectionListenPortStruct *next;
56   struct SilcConfigServerSectionListenPortStruct *prev;
57 } SilcConfigServerSectionListenPort;
58
59 /* Holds all the configured log files. */
60 typedef struct SilcConfigServerSectionLoggingStruct {
61   char *logtype;
62   char *filename;
63   unsigned int maxsize;
64   struct SilcConfigServerSectionLoggingStruct *next;
65   struct SilcConfigServerSectionLoggingStruct *prev;
66
67 /* Allowed <Logging> section types */
68 #define SILC_CONFIG_SERVER_LF_INFO "infologfile"
69 #define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile"
70 #define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile"
71 #define SILC_CONFIG_SERVER_LF_FATAL "fatalogfile"
72 } SilcConfigServerSectionLogging;
73
74 /* Holds all configured connection classes */
75 typedef struct SilcConfigServerSectionConnectionClassStruct {
76   unsigned int class;
77   unsigned int ping_freq;
78   unsigned int connect_freq;
79   unsigned int max_links;
80   struct SilcConfigServerSectionConnectionClassStruct *next;
81   struct SilcConfigServerSectionConnectionClassStruct *prev;
82 } SilcConfigServerSectionConnectionClass;
83
84 #define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd"
85 #define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey"
86
87 /* Holds all client authentication data from config file */
88 typedef struct SilcConfigServerSectionClientConnectionStruct {
89   char *host;
90   int auth_meth;
91   char *auth_data;
92   unsigned short port;
93   unsigned int class;
94   struct SilcConfigServerSectionClientConnectionStruct *next;
95   struct SilcConfigServerSectionClientConnectionStruct *prev;
96 } SilcConfigServerSectionClientConnection;
97
98 /* Hols all server's administrators authentication data from config file */
99 typedef struct SilcConfigServerSectionAdminConnectionStruct {
100   char *host;
101   int auth_meth;
102   char *auth_data;
103   char *nickname;
104   unsigned int class;
105   struct SilcConfigServerSectionAdminConnectionStruct *next;
106   struct SilcConfigServerSectionAdminConnectionStruct *prev;
107 } SilcConfigServerSectionAdminConnection;
108
109 /* Holds all configured server/router connections from config file */
110 typedef struct SilcConfigServerSectionServerConnectionStruct {
111   char *host;
112   int auth_meth;
113   char *auth_data;
114   unsigned short port;
115   char *version;
116   unsigned int class;
117   struct SilcConfigServerSectionServerConnectionStruct *next;
118   struct SilcConfigServerSectionServerConnectionStruct *prev;
119 } SilcConfigServerSectionServerConnection;
120
121 /* Holds all configured denied connections from config file */
122 typedef struct {
123   char *host;
124   char *time;
125   char *comment;
126   unsigned short port;
127 } SilcConfigServerSectionDenyConnection;
128
129 /* Holds all client redirections from config file */
130 typedef struct {
131   char *host;
132   unsigned short port;
133 } SilcConfigServerSectionRedirectClient;
134
135 /* 
136    SILC Server Config object. 
137
138    This object holds all the data parsed from the SILC server configuration
139    file. This is mainly used at the initialization of the server.
140
141 */
142 typedef struct {
143   /* Pointer back to the server */
144   void *server;
145
146   /* Filename of the configuration file */
147   char *filename;
148
149   /* Configuration sections */
150   SilcConfigServerSectionAlg *cipher;
151   SilcConfigServerSectionAlg *pkcs;
152   SilcConfigServerSectionAlg *hash_func;
153   SilcConfigServerSectionServerInfo *server_info;
154   SilcConfigServerSectionAdminInfo *admin_info;
155   SilcConfigServerSectionListenPort *listen_port;
156   SilcConfigServerSectionLogging *logging;
157   SilcConfigServerSectionConnectionClass *conn_class;
158   SilcConfigServerSectionClientConnection *clients;
159   SilcConfigServerSectionServerConnection *servers;
160   SilcConfigServerSectionServerConnection *routers;
161   SilcConfigServerSectionAdminConnection *admins;
162   SilcConfigServerSectionDenyConnection *denied;
163   SilcConfigServerSectionRedirectClient *redirect;
164 } SilcConfigServerObject;
165
166 typedef SilcConfigServerObject *SilcConfigServer;
167
168 /* Configuration section type enumerations. */
169 typedef enum {
170   SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0,
171   SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER,
172   SILC_CONFIG_SERVER_SECTION_TYPE_PKCS,
173   SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION,
174   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO,
175   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO,
176   SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT,
177   SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING,
178   SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS,
179   SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION,
180   SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION,
181   SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION,
182   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
183   SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
184   SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT,
185 } SilcConfigServerSectionType;
186
187 /* SILC Configuration Section structure. */
188 typedef struct {
189   const char *section;
190   SilcConfigServerSectionType type;
191   unsigned int maxfields;
192 } SilcConfigServerSection;
193
194 /* LIst of all possible config sections in SILC server. */
195 extern SilcConfigServerSection silc_config_server_sections[];
196
197 /* Structure used in parsing the configuration lines. The line is read
198    from a file to this structure before parsing it further. */
199 typedef struct SilcConfigServerParseStruct {
200   SilcBuffer line;
201   unsigned int linenum;
202   SilcConfigServerSection *section;
203   struct SilcConfigServerParseStruct *next;
204   struct SilcConfigServerParseStruct *prev;
205 } *SilcConfigServerParse;
206
207 /* Macros */
208
209 /* Allocates list entries for configuration sections. Used by all
210    config sections as this is common. */
211 #define SILC_SERVER_CONFIG_LIST_ALLOC(x)                \
212 do {                                                    \
213   if (!(x)) {                                           \
214     (x) = silc_calloc(1, sizeof(*(x)));                 \
215     (x)->next = NULL;                                   \
216     (x)->prev = NULL;                                   \
217   } else {                                              \
218     if (!(x)->next) {                                   \
219       (x)->next = silc_calloc(1, sizeof(*(x)->next));   \
220       (x)->next->next = NULL;                           \
221       (x)->next->prev = (x);                            \
222       (x) = (x)->next;                                  \
223     }                                                   \
224   }                                                     \
225 } while(0)
226
227 /* Prototypes */
228 SilcConfigServer silc_config_server_alloc(char *filename);
229 void silc_config_server_free(SilcConfigServer config);
230 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
231                              SilcConfigServerParse *return_config);
232 int silc_config_server_parse_lines(SilcConfigServer config, 
233                                    SilcConfigServerParse parse_config);
234 int silc_config_server_check_sections(unsigned int checkmask);
235 void silc_config_server_setlogfiles(SilcConfigServer config);
236 void silc_config_server_register_ciphers(SilcConfigServer config);
237 void silc_config_server_register_pkcs(SilcConfigServer config);
238 void silc_config_server_register_hashfuncs(SilcConfigServer config);
239 SilcConfigServerSectionClientConnection *
240 silc_config_server_find_client_conn(SilcConfigServer config, 
241                                     char *host, int port);
242 SilcConfigServerSectionServerConnection *
243 silc_config_server_find_server_conn(SilcConfigServer config, 
244                                     char *host, int port);
245 SilcConfigServerSectionServerConnection *
246 silc_config_server_find_router_conn(SilcConfigServer config, 
247                                     char *host, int port);
248 void silc_config_server_print();
249
250 #endif