updates.
[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 /* Holds all configured connection classes */
74 /* typedef struct SilcServerConfigSectionClassStruct {
75   uint32 class;
76   uint32 ping_freq;
77   uint32 connect_freq;
78   uint32 max_links;
79   struct SilcServerConfigSectionClassStruct *next;
80 } SilcServerConfigSectionClass; */
81
82 /* Holds all client authentication data from config file */
83 typedef struct SilcServerConfigSectionClientStruct {
84   char *host;
85   unsigned char *passphrase;
86   uint32 passphrase_len;
87   void *publickey;
88   uint16 port;
89   uint32 class;
90   struct SilcServerConfigSectionClientStruct *next;
91 } SilcServerConfigSectionClient;
92
93 /* Holds all server's administrators authentication data from config file */
94 typedef struct SilcServerConfigSectionAdminStruct {
95   char *host;
96   char *user;
97   char *nick;
98   unsigned char *passphrase;
99   uint32 passphrase_len;
100   void *publickey;
101   struct SilcServerConfigSectionAdminStruct *next;
102 } SilcServerConfigSectionAdmin;
103
104 /* Holds all configured denied connections from config file */
105 typedef struct SilcServerConfigSectionDenyStruct {
106   char *host;
107   uint16 port;
108   char *reason;
109   struct SilcServerConfigSectionDenyStruct *next;
110 } SilcServerConfigSectionDeny;
111
112 /* Holds all configured server connections from config file */
113 typedef struct SilcServerConfigSectionServerStruct {
114   char *host;
115   unsigned char *passphrase;
116   uint32 passphrase_len;
117   void *publickey;
118   char *version;
119   uint32 class;
120   bool backup_router;
121   struct SilcServerConfigSectionServerStruct *next;
122 } SilcServerConfigSectionServer;
123
124 /* Holds all configured router connections from config file */
125 typedef struct SilcServerConfigSectionRouterStruct {
126   char *host;
127   unsigned char *passphrase;
128   uint32 passphrase_len;
129   void *publickey;
130   uint16 port;
131   char *version;
132   uint32 class;
133   bool initiator;
134   bool backup_router;
135   char *backup_replace_ip;
136   uint16 backup_replace_port;
137   bool backup_local;
138   struct SilcServerConfigSectionRouterStruct *next;
139 } SilcServerConfigSectionRouter;
140
141 /* define the SilcServerConfig object */
142 typedef struct {
143   void *tmp;
144   char *module_path;
145   bool prefer_passphrase_auth;
146
147   SilcServerConfigSectionCipher *cipher;
148   SilcServerConfigSectionHash *hash;
149   SilcServerConfigSectionHmac *hmac;
150   SilcServerConfigSectionPkcs *pkcs;
151   SilcServerConfigSectionLogging *logging_info;
152   SilcServerConfigSectionLogging *logging_warnings;
153   SilcServerConfigSectionLogging *logging_errors;
154   SilcServerConfigSectionLogging *logging_fatals;
155   SilcServerConfigSectionServerInfo *server_info;
156 /*SilcServerConfigSectionClass *conn_class; */
157   SilcServerConfigSectionClient *clients;
158   SilcServerConfigSectionAdmin *admins;
159   SilcServerConfigSectionDeny *denied;
160   SilcServerConfigSectionServer *servers;
161   SilcServerConfigSectionRouter *routers;
162 } *SilcServerConfig;
163
164 /* Prototypes */
165
166 /* Basic config operations */
167 SilcServerConfig silc_server_config_alloc(char *filename);
168 void silc_server_config_destroy(SilcServerConfig config);
169
170 /* Algorithm registering and reset functions */
171 bool silc_server_config_register_ciphers(SilcServer server);
172 bool silc_server_config_register_hashfuncs(SilcServer server);
173 bool silc_server_config_register_hmacs(SilcServer server);
174 bool silc_server_config_register_pkcs(SilcServer server);
175 void silc_server_config_setlogfiles(SilcServer server);
176
177 /* Run-time config access functions */
178 SilcServerConfigSectionClient *
179 silc_server_config_find_client(SilcServer server, char *host, int port);
180 SilcServerConfigSectionAdmin *
181 silc_server_config_find_admin(SilcServer server, char *host, char *user, 
182                               char *nick);
183 SilcServerConfigSectionDeny *
184 silc_server_config_find_denied(SilcServer server, char *host, uint16 port);
185 SilcServerConfigSectionServer *
186 silc_server_config_find_server_conn(SilcServer server, char *host);
187 SilcServerConfigSectionRouter *
188 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
189 bool silc_server_config_is_primary_route(SilcServer server);
190 SilcServerConfigSectionRouter *
191 silc_server_config_get_primary_router(SilcServer server);
192
193 #endif  /* !SERVERCONFIG_H */