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