ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-newconf/src/conf/serverinfo.c
Revision: 1027
Committed: Sun Nov 8 13:01:13 2009 UTC (16 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 7505 byte(s)
Log Message:
- Move old 7.3 sources to branches/ircd-hybrid-newconf

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * serverinfo.c: Defines the serverinfo{} block of ircd.conf.
4 *
5 * Copyright (C) 2005 by the Hybrid Development Team.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "conf/conf.h"
27 #include "client.h"
28 #include "hash.h"
29 #include "ircd.h"
30 #include "server.h"
31 #include "user.h"
32
33 struct ServerInfoConf ServerInfo = {0};
34
35 static dlink_node *hreset, *hverify;
36
37 /*
38 * reset_serverinfo()
39 *
40 * Sets up default values before a rehash.
41 *
42 * inputs: none
43 * output: none
44 */
45 static void *
46 reset_serverinfo(va_list args)
47 {
48 memset(&ServerInfo.vhost, 0, sizeof(ServerInfo.vhost));
49 #ifdef IPV6
50 memset(&ServerInfo.vhost6, 0, sizeof(ServerInfo.vhost6));
51 #endif
52 ServerInfo.hub = NO;
53 ServerInfo.max_clients = 512;
54
55 if (!ServerInfo.network_name)
56 DupString(ServerInfo.network_name, "EFnet");
57
58 return pass_callback(hreset);
59 }
60
61 /*
62 * verify_serverinfo()
63 *
64 * Checks if required settings are defined.
65 *
66 * inputs: none
67 * output: none
68 */
69 static void *
70 verify_serverinfo(va_list args)
71 {
72 char *p;
73
74 if (!me.name[0])
75 parse_fatal("name= field missing in serverinfo{} section");
76
77 if (!me.info[0])
78 parse_fatal("description= field missing in serverinfo{} section");
79
80 add_isupport("NETWORK", ServerInfo.network_name, -1);
81
82 if ((p = strchr(ServerInfo.network_name, ' ')) != NULL)
83 *p = 0;
84
85 if (ServerInfo.network_desc == NULL)
86 DupString(ServerInfo.network_desc, ServerInfo.network_name);
87
88 if (conf_cold)
89 {
90 hash_add_client(&me);
91 if (me.id[0])
92 {
93 hash_add_id(&me);
94 memcpy(new_uid, me.id, IRC_MAXSID);
95 }
96 }
97
98 recalc_fdlimit(NULL);
99
100 if (ServerInfo.max_clients < MAXCLIENTS_MIN)
101 {
102 parse_error("MAXCLIENTS=%d too low, setting to %d",
103 ServerInfo.max_clients, MAXCLIENTS_MIN);
104
105 ServerInfo.max_clients = MAXCLIENTS_MIN;
106 }
107 else if (ServerInfo.max_clients > MAXCLIENTS_MAX)
108 {
109 parse_error("MAXCLIENTS=%d too high, setting to %d",
110 ServerInfo.max_clients, MAXCLIENTS_MAX);
111
112 ServerInfo.max_clients = MAXCLIENTS_MAX;
113 }
114
115 return pass_callback(hverify);
116 }
117
118 static void
119 si_set_name(void *value, void *unused)
120 {
121 char *name = (char *) value;
122
123 if (strlen(name) > HOSTLEN)
124 {
125 if (conf_cold)
126 parse_fatal("server name too long (max %d)", HOSTLEN);
127 else
128 parse_error("server name too long (max %d)", HOSTLEN);
129 }
130 else if (conf_cold)
131 strcpy(me.name, name);
132 else if (strcmp(me.name, name) != 0)
133 parse_error("cannot change server name on rehash");
134 }
135
136 static void
137 si_set_sid(void *value, void *unused)
138 {
139 char *sid = (char *) value;
140
141 /* XXX */
142 if (!IsDigit(sid[0]) || !IsAlNum(sid[1]) || !IsAlNum(sid[2]) || sid[3] != 0)
143 parse_error("invalid SID, must match [0-9][0-9A-Z][0-9A-Z]");
144 else if (conf_cold)
145 strcpy(me.id, sid);
146 else if (strcmp(me.id, sid) != 0)
147 parse_error("cannot change SID on rehash");
148 }
149
150 static void
151 si_set_description(void *value, void *unused)
152 {
153 strlcpy(me.info, (char *) value, sizeof(me.info));
154 }
155
156 static void
157 si_set_vhost(void *value, void *where)
158 {
159 char *addrstr = (char *) value;
160 struct irc_ssaddr *dest = (struct irc_ssaddr *) where;
161 struct addrinfo hints, *res;
162
163 if (*addrstr == '*')
164 return;
165
166 memset(&hints, 0, sizeof(hints));
167
168 #ifdef IPV6
169 hints.ai_family = (where == ServerInfo.vhost6 ? AF_INET6 : AF_INET);
170 #else
171 hints.ai_family = AF_INET;
172 #endif
173 hints.ai_socktype = SOCK_STREAM;
174 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
175
176 if (irc_getaddrinfo(addrstr, NULL, &hints, &res))
177 parse_error("invalid netmask");
178 else
179 {
180 memcpy(dest, res->ai_addr, res->ai_addrlen);
181 dest->ss.sin_family = res->ai_family;
182 dest->ss_len = res->ai_addrlen;
183 irc_freeaddrinfo(res);
184 }
185 }
186
187 static void
188 si_set_rsa_private_key(void *value, void *unused)
189 {
190 #ifndef HAVE_LIBCRYPTO
191 parse_error("no OpenSSL support");
192 #else
193 BIO *file;
194
195 MyFree(ServerInfo.rsa_private_key_file);
196 ServerInfo.rsa_private_key_file = NULL;
197
198 if (ServerInfo.rsa_private_key)
199 {
200 RSA_free(ServerInfo.rsa_private_key);
201 ServerInfo.rsa_private_key = NULL;
202 }
203
204 if ((file = BIO_new_file(value, "r")) == NULL)
205 {
206 parse_error("file doesn't exist");
207 return;
208 }
209
210 ServerInfo.rsa_private_key = (RSA *) PEM_read_bio_RSAPrivateKey(file, NULL,
211 0, NULL);
212
213 BIO_set_close(file, BIO_CLOSE);
214 BIO_free(file);
215
216 if (!ServerInfo.rsa_private_key)
217 parse_error("key invalid; check key syntax");
218 else if (!RSA_check_key(ServerInfo.rsa_private_key))
219 {
220 RSA_free(ServerInfo.rsa_private_key);
221 ServerInfo.rsa_private_key = NULL;
222 parse_error("invalid key, ignoring");
223 }
224 else if (RSA_size(ServerInfo.rsa_private_key) != 2048/8)
225 {
226 RSA_free(ServerInfo.rsa_private_key);
227 ServerInfo.rsa_private_key = NULL;
228 parse_error("not a 2048-bit key, ignoring");
229 }
230 else
231 DupString(ServerInfo.rsa_private_key_file, value);
232 #endif
233 }
234
235 static void
236 si_set_ssl_certificate(void *value, void *unused)
237 {
238 #ifndef HAVE_LIBCRYPTO
239 parse_error("no OpenSSL support");
240 #else
241 if (!ServerInfo.rsa_private_key)
242 parse_error("put a valid rsa_private_key_file before this line");
243 else if (SSL_CTX_use_certificate_file(ServerInfo.ctx, value,
244 SSL_FILETYPE_PEM) <= 0)
245 parse_error(ERR_lib_error_string(ERR_get_error()));
246 else if (SSL_CTX_use_PrivateKey_file(ServerInfo.ctx,
247 ServerInfo.rsa_private_key_file, SSL_FILETYPE_PEM) <= 0)
248 parse_error(ERR_lib_error_string(ERR_get_error()));
249 else if (!SSL_CTX_check_private_key(ServerInfo.ctx))
250 parse_error("RSA private key does not match "
251 "the SSL certificate public key");
252 #endif
253 }
254
255 /*
256 * init_serverinfo()
257 *
258 * Defines the serverhide{} conf section.
259 *
260 * inputs: none
261 * output: none
262 */
263 void
264 init_serverinfo(void)
265 {
266 struct ConfSection *s = add_conf_section("serverinfo", 1);
267
268 hreset = install_hook(reset_conf, reset_serverinfo);
269 hverify = install_hook(verify_conf, verify_serverinfo);
270
271 add_conf_field(s, "name", CT_STRING, si_set_name, NULL);
272 add_conf_field(s, "sid", CT_STRING, si_set_sid, NULL);
273 add_conf_field(s, "description", CT_STRING, si_set_description, NULL);
274 add_conf_field(s, "network_name", CT_STRING, NULL, &ServerInfo.network_name);
275 add_conf_field(s, "network_desc", CT_STRING, NULL, &ServerInfo.network_desc);
276 add_conf_field(s, "hub", CT_BOOL, NULL, &ServerInfo.hub);
277 add_conf_field(s, "vhost", CT_STRING, si_set_vhost, &ServerInfo.vhost);
278 #ifdef IPV6
279 add_conf_field(s, "vhost6", CT_STRING, si_set_vhost, &ServerInfo.vhost6);
280 #endif
281 add_conf_field(s, "max_clients", CT_NUMBER, NULL, &ServerInfo.max_clients);
282 #ifdef HAVE_LIBCRYPTO
283 add_conf_field(s, "rsa_private_key_file", CT_STRING, si_set_rsa_private_key,
284 NULL);
285 add_conf_field(s, "ssl_certificate_file", CT_STRING, si_set_ssl_certificate,
286 NULL);
287 #endif
288 }

Properties

Name Value
svn:eol-style native
svn:keywords "Id Revision"