5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
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.
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.
23 * Revision 1.4 2000/10/06 08:10:23 priikone
24 * Added WHOIS to send multiple replies if multiple nicknames are
26 * Added MOTD command and [motd] config section and server also sends
27 * motd to client on connection now.
28 * Fixed TOPIC command some more.
30 * Revision 1.3 2000/07/10 05:41:20 priikone
31 * Added missing token to administrative information.
33 * Revision 1.2 2000/07/05 06:14:01 priikone
34 * Global costemic changes.
36 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
37 * Imported from internal CVS/Added Log headers.
42 #include "serverincludes.h"
43 #include "server_internal.h"
46 All possible configuration sections for SILC server.
52 +<Cipher name>:<SIM path>
58 +<PKCS name>:<key length>
64 +<Hash function name>:<SIM path>
68 This section is used to set the server informations.
72 +<Server DNS name>:<Server IP>:<Geographic location>:<Port>
76 This section is used to set the server's administrative information.
80 +<Location>:<Server type>:<Admin's name>:<Admin's email address>
84 This section is used to set ports the server is listenning.
88 +<Local IP/UNIX socket path>:<Remote IP>:<Port>
92 This section is used to set various logging files, their paths
93 and maximum sizes. All the other directives except those defined
94 below are ignored in this section. Log files are purged after they
95 reach the maximum set byte size.
99 +infologfile:<path>:<max byte size>
100 +errorlogfile:<path>:<max byte size>
104 This section is used to define connection classes. These can be
105 used to optimize the server and the connections.
109 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
113 This section is used to define client authentications.
117 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
121 This section is used to define the server's administration
126 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
130 This section is used to define the server connections to this
131 server/router. Only routers can have normal server connections.
132 Normal servers leave this section epmty. The remote server cannot be
133 older than specified Version ID.
137 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
141 This section is used to define the router connections to this
142 server/router. Both normal server and router can have router
143 connections. Normal server usually has only one connection while
144 a router can have multiple. The remote server cannot be older than
145 specified Version ID.
149 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
153 This section is used to deny specific connections to your server. This
154 can be used to deny both clients and servers.
158 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
162 This section is used to set the alternate servers that clients will be
163 redirected to when our server is full.
167 +<Remote address or name>:<Port>
170 SilcConfigServerSection silc_config_server_sections[] = {
172 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
174 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
176 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
178 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
180 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
182 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
184 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
185 { "[ConnectionClass]",
186 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
187 { "[ClientConnection]",
188 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
189 { "[ServerConnection]",
190 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
191 { "[RouterConnection]",
192 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 6 },
193 { "[AdminConnection]",
194 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
195 { "[DenyConnection]",
196 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
197 { "[RedirectClient]",
198 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
200 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
202 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
205 /* Allocates a new configuration object, opens configuration file and
206 parses the file. The parsed data is returned to the newly allocated
207 configuration object. */
209 SilcConfigServer silc_config_server_alloc(char *filename)
211 SilcConfigServer new;
213 SilcConfigServerParse config_parse;
215 SILC_LOG_DEBUG(("Allocating new configuration object"));
217 new = silc_calloc(1, sizeof(*new));
219 fprintf(stderr, "Could not allocate new configuration object");
223 new->filename = filename;
225 /* Open configuration file and parse it */
228 silc_config_open(filename, &buffer);
231 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
233 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
245 /* Free's a configuration object. */
247 void silc_config_server_free(SilcConfigServer config)
250 silc_free(config->filename);
251 silc_free(config->server_info);
252 silc_free(config->admin_info);
253 silc_free(config->listen_port);
254 silc_free(config->conn_class);
255 silc_free(config->clients);
256 silc_free(config->admins);
257 silc_free(config->servers);
258 silc_free(config->routers);
259 silc_free(config->denied);
260 silc_free(config->redirect);
261 silc_free(config->motd);
266 /* Parses the the buffer and returns the parsed lines into return_config
267 argument. The return_config argument doesn't have to be initialized
268 before calling this. It will be initialized during the parsing. The
269 buffer sent as argument can be safely free'd after this function has
270 succesfully returned. */
272 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
273 SilcConfigServerParse *return_config)
276 unsigned int linenum;
277 char line[1024], *cp;
278 SilcConfigServerSection *cptr = NULL;
279 SilcConfigServerParse parse = *return_config, first = NULL;
281 SILC_LOG_DEBUG(("Parsing configuration file"));
285 while((begin = silc_gets(line, sizeof(line),
286 buffer->data, buffer->len, begin)) != EOF) {
290 /* Check for bad line */
291 if (silc_check_line(cp))
294 /* Remove tabs and whitespaces from the line */
295 if (strchr(cp, '\t')) {
297 while(strchr(cp + i, '\t')) {
298 *strchr(cp + i, '\t') = ' ';
302 for (i = 0; i < strlen(cp); i++) {
318 /* Remove new line sign */
319 if (strchr(cp, '\n'))
320 *strchr(cp, '\n') = '\0';
322 /* Check for matching sections */
323 for (cptr = silc_config_server_sections; cptr->section; cptr++)
324 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
327 if (!cptr->section) {
328 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
329 config->filename, linenum, cp);
336 * Start of a configuration line
339 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
341 if (strchr(cp, '\n'))
342 *strchr(cp, '\n') = ':';
345 parse = silc_calloc(1, sizeof(*parse));
347 parse->section = NULL;
351 if (parse->next == NULL) {
352 parse->next = silc_calloc(1, sizeof(*parse->next));
353 parse->next->line = NULL;
354 parse->next->section = NULL;
355 parse->next->next = NULL;
356 parse->next->prev = parse;
364 /* Add the line to parsing structure for further parsing. */
366 parse->section = cptr;
367 parse->line = silc_buffer_alloc(strlen(cp) + 1);
368 parse->linenum = linenum;
369 silc_buffer_pull_tail(parse->line, strlen(cp));
370 silc_buffer_put(parse->line, cp, strlen(cp));
377 /* Set the return_config argument to its first value so that further
378 parsing can be started from the first line. */
379 *return_config = first;
384 /* Parses the lines earlier read from configuration file. The config object
385 must not be initialized, it will be initialized in this function. The
386 parse_config argument is uninitialized automatically during this
389 int silc_config_server_parse_lines(SilcConfigServer config,
390 SilcConfigServerParse parse_config)
392 int ret, check = FALSE;
393 unsigned int checkmask;
395 SilcConfigServerParse pc = parse_config;
398 SILC_LOG_DEBUG(("Parsing configuration lines"));
408 /* Get number of tokens in line */
409 ret = silc_config_check_num_token(line);
410 if (ret != pc->section->maxfields) {
412 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
413 config->filename, pc->linenum, ret,
414 pc->section->maxfields);
419 switch(pc->section->type) {
420 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
422 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
424 /* Get cipher name */
425 ret = silc_config_get_token(line, &config->cipher->alg_name);
429 fprintf(stderr, "%s:%d: Cipher name not defined\n",
430 config->filename, pc->linenum);
434 /* Get module name */
435 config->cipher->sim_name = NULL;
436 ret = silc_config_get_token(line, &config->cipher->sim_name);
440 /* Get block length */
441 ret = silc_config_get_token(line, &tmp);
445 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
446 config->filename, pc->linenum);
449 config->cipher->block_len = atoi(tmp);
453 ret = silc_config_get_token(line, &tmp);
457 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
458 config->filename, pc->linenum);
461 config->cipher->key_len = atoi(tmp);
465 checkmask |= (1L << pc->section->type);
468 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
470 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
473 ret = silc_config_get_token(line, &config->pkcs->alg_name);
477 fprintf(stderr, "%s:%d: PKCS name not defined\n",
478 config->filename, pc->linenum);
483 ret = silc_config_get_token(line, &tmp);
487 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
488 config->filename, pc->linenum);
491 config->pkcs->key_len = atoi(tmp);
495 checkmask |= (1L << pc->section->type);
498 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
500 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
502 /* Get Hash function name */
503 ret = silc_config_get_token(line, &config->hash_func->alg_name);
507 fprintf(stderr, "%s:%d: Hash function name not defined\n",
508 config->filename, pc->linenum);
512 /* Get Hash function module name */
513 config->hash_func->sim_name = NULL;
514 ret = silc_config_get_token(line, &config->hash_func->sim_name);
518 /* Get block length */
519 ret = silc_config_get_token(line, &tmp);
523 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
524 config->filename, pc->linenum);
527 config->hash_func->block_len = atoi(tmp);
530 /* Get hash length */
531 ret = silc_config_get_token(line, &tmp);
535 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
536 config->filename, pc->linenum);
539 config->hash_func->key_len = atoi(tmp);
543 checkmask |= (1L << pc->section->type);
546 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
548 if (!config->server_info)
549 config->server_info = silc_calloc(1, sizeof(*config->server_info));
551 /* Get server name */
552 ret = silc_config_get_token(line, &config->server_info->server_name);
556 /* Server name not defined */
561 ret = silc_config_get_token(line, &config->server_info->server_ip);
565 /* Server IP not defined */
569 /* Get server location */
570 ret = silc_config_get_token(line, &config->server_info->location);
574 /* Get server port */
575 /* XXX: Need port here??? */
576 ret = silc_config_get_token(line, &tmp);
580 /* Port not defined */
583 config->server_info->port = atoi(tmp);
587 checkmask |= (1L << pc->section->type);
590 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
592 if (!config->admin_info)
593 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
596 ret = silc_config_get_token(line, &config->admin_info->location);
600 /* Get server type */
601 ret = silc_config_get_token(line, &config->admin_info->server_type);
605 /* Get admins name */
606 ret = silc_config_get_token(line, &config->admin_info->admin_name);
610 /* Get admins email address */
611 ret = silc_config_get_token(line, &config->admin_info->admin_email);
616 checkmask |= (1L << pc->section->type);
619 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
621 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
624 ret = silc_config_get_token(line, &config->listen_port->host);
629 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
634 ret = silc_config_get_token(line, &tmp);
639 config->listen_port->port = 0;
641 config->listen_port->port = atoi(tmp);
646 checkmask |= (1L << pc->section->type);
649 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
651 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
653 /* Get class number */
654 ret = silc_config_get_token(line, &tmp);
658 /* Class number not defined */
661 config->conn_class->class = atoi(tmp);
664 /* Get ping frequency */
665 ret = silc_config_get_token(line, &tmp);
668 config->conn_class->ping_freq = atoi(tmp);
671 /* Get connect frequency */
672 ret = silc_config_get_token(line, &tmp);
675 config->conn_class->connect_freq = atoi(tmp);
679 ret = silc_config_get_token(line, &tmp);
682 config->conn_class->max_links = atoi(tmp);
686 checkmask |= (1L << pc->section->type);
689 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
691 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
693 /* Get log section type and check it */
694 ret = silc_config_get_token(line, &config->logging->logtype);
698 fprintf(stderr, "%s:%d: Log file section not defined\n",
699 config->filename, pc->linenum);
702 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
703 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
704 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
705 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
706 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
707 config->filename, pc->linenum, config->logging->logtype);
711 /* Get log filename */
712 ret = silc_config_get_token(line, &config->logging->filename);
716 fprintf(stderr, "%s:%d: Log file name not defined\n",
717 config->filename, pc->linenum);
721 /* Get max byte size */
722 ret = silc_config_get_token(line, &tmp);
726 config->logging->maxsize = atoi(tmp);
731 checkmask |= (1L << pc->section->type);
734 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
736 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
739 ret = silc_config_get_token(line, &config->clients->host);
744 config->clients->host = strdup("*");
746 /* Get authentication method */
747 ret = silc_config_get_token(line, &tmp);
751 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
752 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
753 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
754 config->filename, pc->linenum, tmp);
758 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
759 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
761 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
762 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
767 /* Get authentication data */
768 ret = silc_config_get_token(line, &config->clients->auth_data);
773 config->clients->host = strdup("*");
776 ret = silc_config_get_token(line, &tmp);
780 config->clients->port = atoi(tmp);
784 /* Get class number */
785 ret = silc_config_get_token(line, &tmp);
789 config->clients->class = atoi(tmp);
794 checkmask |= (1L << pc->section->type);
797 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
799 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
802 ret = silc_config_get_token(line, &config->servers->host);
807 config->servers->host = strdup("*");
809 /* Get authentication method */
810 ret = silc_config_get_token(line, &tmp);
814 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
815 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
816 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
817 config->filename, pc->linenum, tmp);
821 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
822 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
824 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
825 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
830 /* Get authentication data */
831 ret = silc_config_get_token(line, &config->servers->auth_data);
836 ret = silc_config_get_token(line, &tmp);
840 config->servers->port = atoi(tmp);
845 ret = silc_config_get_token(line, &config->servers->version);
849 /* Get class number */
850 ret = silc_config_get_token(line, &tmp);
854 config->servers->class = atoi(tmp);
859 checkmask |= (1L << pc->section->type);
862 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
864 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
867 ret = silc_config_get_token(line, &config->routers->host);
872 // config->routers->host = strdup("*");
874 /* Get authentication method */
875 ret = silc_config_get_token(line, &tmp);
879 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
880 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
881 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
882 config->filename, pc->linenum, tmp);
886 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
887 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
889 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
890 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
895 /* Get authentication data */
896 ret = silc_config_get_token(line, &config->routers->auth_data);
901 ret = silc_config_get_token(line, &tmp);
905 config->routers->port = atoi(tmp);
910 ret = silc_config_get_token(line, &config->routers->version);
914 /* Get class number */
915 ret = silc_config_get_token(line, &tmp);
919 config->routers->class = atoi(tmp);
924 checkmask |= (1L << pc->section->type);
927 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
929 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
932 ret = silc_config_get_token(line, &config->admins->host);
937 config->admins->host = strdup("*");
939 /* Get authentication method */
940 ret = silc_config_get_token(line, &tmp);
944 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
945 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
946 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
947 config->filename, pc->linenum, tmp);
951 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
952 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
954 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
955 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
960 /* Get authentication data */
961 ret = silc_config_get_token(line, &config->admins->auth_data);
966 ret = silc_config_get_token(line, &config->admins->nickname);
970 /* Get class number */
971 ret = silc_config_get_token(line, &tmp);
975 config->admins->class = atoi(tmp);
980 checkmask |= (1L << pc->section->type);
983 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
984 /* Not implemented yet */
988 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
989 /* Not implemented yet */
993 case SILC_CONFIG_SERVER_SECTION_TYPE_MOTD:
996 config->motd = silc_calloc(1, sizeof(*config->motd));
999 ret = silc_config_get_token(line, &config->motd->motd_file);
1004 checkmask |= (1L << pc->section->type);
1007 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
1013 /* Check for error */
1014 if (check == FALSE) {
1015 /* Line could not be parsed */
1016 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
1022 // silc_free(pc->prev);
1029 /* Check that all mandatory sections really were found. If not, the server
1030 cannot function and we return error. */
1031 ret = silc_config_server_check_sections(checkmask);
1037 /* Before returning all the lists in the config object must be set
1038 to their first values (the last value is first here). */
1039 while (config->cipher && config->cipher->prev)
1040 config->cipher = config->cipher->prev;
1041 while (config->pkcs && config->pkcs->prev)
1042 config->pkcs = config->pkcs->prev;
1043 while (config->hash_func && config->hash_func->prev)
1044 config->hash_func = config->hash_func->prev;
1045 while (config->listen_port && config->listen_port->prev)
1046 config->listen_port = config->listen_port->prev;
1047 while (config->logging && config->logging->prev)
1048 config->logging = config->logging->prev;
1049 while (config->conn_class && config->conn_class->prev)
1050 config->conn_class = config->conn_class->prev;
1051 while (config->clients && config->clients->prev)
1052 config->clients = config->clients->prev;
1053 while (config->servers && config->servers->prev)
1054 config->servers = config->servers->prev;
1055 while (config->routers && config->routers->prev)
1056 config->routers = config->routers->prev;
1058 SILC_LOG_DEBUG(("Done"));
1063 /* This function checks that the mask sent as argument includes all the
1064 sections that are mandatory in SILC server. */
1066 int silc_config_server_check_sections(unsigned int checkmask)
1068 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1072 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1076 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1080 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1085 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1090 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1098 /* Sets log files where log messages is saved by the server. */
1100 void silc_config_server_setlogfiles(SilcConfigServer config)
1102 SilcConfigServerSectionLogging *log;
1103 char *info, *warning, *error, *fatal;
1104 unsigned int info_size, warning_size, error_size, fatal_size;
1106 SILC_LOG_DEBUG(("Setting configured log file names"));
1108 /* Set default files before checking configuration */
1109 info = SILC_LOG_FILE_INFO;
1110 warning = SILC_LOG_FILE_WARNING;
1111 error = SILC_LOG_FILE_ERROR;
1112 fatal = SILC_LOG_FILE_FATAL;
1118 log = config->logging;
1120 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1121 info = log->filename;
1122 info_size = log->maxsize;
1124 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1125 warning = log->filename;
1126 warning_size = log->maxsize;
1128 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1129 error = log->filename;
1130 error_size = log->maxsize;
1132 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1133 fatal = log->filename;
1134 fatal_size = log->maxsize;
1140 silc_log_set_files(info, info_size, warning, warning_size,
1141 error, error_size, fatal, fatal_size);
1144 /* Registers configured ciphers. These can then be allocated by the
1145 server when needed. */
1147 void silc_config_server_register_ciphers(SilcConfigServer config)
1149 SilcConfigServerSectionAlg *alg;
1150 SilcServer server = (SilcServer)config->server;
1152 SILC_LOG_DEBUG(("Registering configured ciphers"));
1154 alg = config->cipher;
1157 if (!alg->sim_name) {
1158 /* Crypto module is supposed to be built in. Nothing to be done
1159 here except to test that the cipher really is built in. */
1160 SilcCipher tmp = NULL;
1162 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1163 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1164 silc_server_stop(server);
1167 silc_cipher_free(tmp);
1171 /* Load (try at least) the crypto SIM module */
1172 SilcCipherObject cipher;
1173 SilcSimContext *sim;
1175 memset(&cipher, 0, sizeof(cipher));
1176 cipher.name = alg->alg_name;
1177 cipher.block_len = alg->block_len;
1178 cipher.key_len = alg->key_len * 8;
1180 sim = silc_sim_alloc();
1181 sim->type = SILC_SIM_CIPHER;
1182 sim->libname = alg->sim_name;
1184 if ((silc_sim_load(sim))) {
1186 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1187 SILC_CIPHER_SIM_SET_KEY));
1188 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1189 cipher.set_key_with_string =
1190 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1191 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1192 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1194 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1195 SILC_CIPHER_SIM_ENCRYPT_CBC));
1196 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1198 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1199 SILC_CIPHER_SIM_DECRYPT_CBC));
1200 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1201 cipher.context_len =
1202 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1203 SILC_CIPHER_SIM_CONTEXT_LEN));
1204 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1206 /* Put the SIM to the table of all SIM's in server */
1207 server->sim = silc_realloc(server->sim,
1208 sizeof(*server->sim) *
1209 (server->sim_count + 1));
1210 server->sim[server->sim_count] = sim;
1211 server->sim_count++;
1213 SILC_LOG_ERROR(("Error configuring ciphers"));
1214 silc_server_stop(server);
1218 /* Register the cipher */
1219 silc_cipher_register(&cipher);
1227 /* Registers configured PKCS's. */
1228 /* XXX: This really doesn't do anything now since we have statically
1229 registered our PKCS's. This should be implemented when PKCS works
1230 as SIM's. This checks now only that the PKCS user requested is
1231 really out there. */
1233 void silc_config_server_register_pkcs(SilcConfigServer config)
1235 SilcConfigServerSectionAlg *alg = config->pkcs;
1236 SilcServer server = (SilcServer)config->server;
1237 SilcPKCS tmp = NULL;
1239 SILC_LOG_DEBUG(("Registering configured PKCS"));
1243 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1244 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1245 silc_server_stop(server);
1254 /* Registers configured hash functions. These can then be allocated by the
1255 server when needed. */
1257 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1259 SilcConfigServerSectionAlg *alg;
1260 SilcServer server = (SilcServer)config->server;
1262 SILC_LOG_DEBUG(("Registering configured hash functions"));
1264 alg = config->hash_func;
1267 if (!alg->sim_name) {
1268 /* Hash module is supposed to be built in. Nothing to be done
1269 here except to test that the hash function really is built in. */
1270 SilcHash tmp = NULL;
1272 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1273 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1274 silc_server_stop(server);
1281 /* Load (try at least) the hash SIM module */
1282 SilcHashObject hash;
1283 SilcSimContext *sim;
1285 memset(&hash, 0, sizeof(hash));
1286 hash.name = alg->alg_name;
1287 hash.block_len = alg->block_len;
1288 hash.hash_len = alg->key_len;
1290 sim = silc_sim_alloc();
1291 sim->type = SILC_SIM_HASH;
1292 sim->libname = alg->sim_name;
1294 if ((silc_sim_load(sim))) {
1296 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1297 SILC_HASH_SIM_INIT));
1298 SILC_LOG_DEBUG(("init=%p", hash.init));
1300 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1301 SILC_HASH_SIM_UPDATE));
1302 SILC_LOG_DEBUG(("update=%p", hash.update));
1304 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1305 SILC_HASH_SIM_FINAL));
1306 SILC_LOG_DEBUG(("final=%p", hash.final));
1308 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1309 SILC_HASH_SIM_CONTEXT_LEN));
1310 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1312 /* Put the SIM to the table of all SIM's in server */
1313 server->sim = silc_realloc(server->sim,
1314 sizeof(*server->sim) *
1315 (server->sim_count + 1));
1316 server->sim[server->sim_count] = sim;
1317 server->sim_count++;
1319 SILC_LOG_ERROR(("Error configuring hash functions"));
1320 silc_server_stop(server);
1324 /* Register the cipher */
1325 silc_hash_register(&hash);
1333 /* Returns client authentication information from server configuration
1334 by host (name or ip). */
1336 SilcConfigServerSectionClientConnection *
1337 silc_config_server_find_client_conn(SilcConfigServer config,
1338 char *host, int port)
1341 SilcConfigServerSectionClientConnection *client = NULL;
1346 if (!config->clients)
1349 client = config->clients;
1351 for (i = 0; client; i++) {
1352 if (silc_string_compare(client->host, host))
1354 client = client->next;
1363 /* Returns server connection info from server configuartion by host
1366 SilcConfigServerSectionServerConnection *
1367 silc_config_server_find_server_conn(SilcConfigServer config,
1368 char *host, int port)
1371 SilcConfigServerSectionServerConnection *serv = NULL;
1376 if (!config->servers)
1379 serv = config->servers;
1380 for (i = 0; serv; i++) {
1381 if (silc_string_compare(serv->host, host))
1392 /* Returns router connection info from server configuartion by
1393 host (name or ip). */
1395 SilcConfigServerSectionServerConnection *
1396 silc_config_server_find_router_conn(SilcConfigServer config,
1397 char *host, int port)
1400 SilcConfigServerSectionServerConnection *serv = NULL;
1405 if (!config->routers)
1408 serv = config->routers;
1409 for (i = 0; serv; i++) {
1410 if (silc_string_compare(serv->host, host))
1421 /* Prints out example configuration file with default built in
1422 configuration values. */
1424 void silc_config_server_print()
1430 # Automatically generated example SILCd configuration file with default\n\
1431 # built in values. Use this as a guide to configure your SILCd configuration\n\
1432 # file for your system. For detailed description of different configuration\n\
1433 # sections refer to silcd(8) manual page.\n\
1448 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1451 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1454 +10.2.1.6:10.2.1.6:1333
1457 +infologfile:silcd.log:10000
1458 #+warninglogfile:/var/log/silcd_warning.log:10000
1459 #+errorlogfile:ERROR.log:10000
1460 #+fatallogfile:/var/log/silcd_error.log:
1467 +10.2.1.199:priikone:333:1
1470 +10.2.1.199:priikone:priikone:1
1480 fprintf(stdout, "%s\n", buf);