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.1 2000/06/27 11:36:56 priikone
29 #include "serverincludes.h"
30 #include "server_internal.h"
33 All possible configuration sections for SILC server.
39 +<Cipher name>:<SIM path>
45 +<PKCS name>:<key length>
51 +<Hash function name>:<SIM path>
55 This section is used to set the server informations.
59 +<Server DNS name>:<Server IP>:<Geographic location>:<Port>
63 This section is used to set the server's administrative information.
67 +<Location>:<Server type>:<Admin's name>:<Admin's email address>
71 This section is used to set ports the server is listenning.
75 +<Local IP/UNIX socket path>:<Remote IP>:<Port>
79 This section is used to set various logging files, their paths
80 and maximum sizes. All the other directives except those defined
81 below are ignored in this section. Log files are purged after they
82 reach the maximum set byte size.
86 +infologfile:<path>:<max byte size>
87 +errorlogfile:<path>:<max byte size>
91 This section is used to define connection classes. These can be
92 used to optimize the server and the connections.
96 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
100 This section is used to define client authentications.
104 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
108 This section is used to define the server's administration
113 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
117 This section is used to define the server connections to this
118 server/router. Only routers can have normal server connections.
119 Normal servers leave this section epmty. The remote server cannot be
120 older than specified Version ID.
124 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
128 This section is used to define the router connections to this
129 server/router. Both normal server and router can have router
130 connections. Normal server usually has only one connection while
131 a router can have multiple. The remote server cannot be older than
132 specified Version ID.
136 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
140 This section is used to deny specific connections to your server. This
141 can be used to deny both clients and servers.
145 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
149 This section is used to set the alternate servers that clients will be
150 redirected to when our server is full.
154 +<Remote address or name>:<Port>
157 SilcConfigServerSection silc_config_server_sections[] = {
159 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
161 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
163 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
165 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
167 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
169 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
171 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
172 { "[ConnectionClass]",
173 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
174 { "[ClientConnection]",
175 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
176 { "[ServerConnection]",
177 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
178 { "[RouterConnection]",
179 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 6 },
180 { "[AdminConnection]",
181 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
182 { "[DenyConnection]",
183 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
184 { "[RedirectClient]",
185 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
187 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
190 /* Allocates a new configuration object, opens configuration file and
191 parses the file. The parsed data is returned to the newly allocated
192 configuration object. */
194 SilcConfigServer silc_config_server_alloc(char *filename)
196 SilcConfigServer new;
198 SilcConfigServerParse config_parse;
200 SILC_LOG_DEBUG(("Allocating new configuration object"));
202 new = silc_calloc(1, sizeof(*new));
204 fprintf(stderr, "Could not allocate new configuration object");
208 new->filename = filename;
210 /* Open configuration file and parse it */
213 silc_config_open(filename, &buffer);
216 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
218 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
230 /* Free's a configuration object. */
232 void silc_config_server_free(SilcConfigServer config)
235 silc_free(config->filename);
236 silc_free(config->server_info);
237 silc_free(config->admin_info);
238 silc_free(config->listen_port);
239 silc_free(config->conn_class);
240 silc_free(config->clients);
241 silc_free(config->admins);
242 silc_free(config->servers);
243 silc_free(config->routers);
244 silc_free(config->denied);
245 silc_free(config->redirect);
250 /* Parses the the buffer and returns the parsed lines into return_config
251 argument. The return_config argument doesn't have to be initialized
252 before calling this. It will be initialized during the parsing. The
253 buffer sent as argument can be safely free'd after this function has
254 succesfully returned. */
256 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
257 SilcConfigServerParse *return_config)
260 unsigned int linenum;
261 char line[1024], *cp;
262 SilcConfigServerSection *cptr = NULL;
263 SilcConfigServerParse parse = *return_config, first = NULL;
265 SILC_LOG_DEBUG(("Parsing configuration file"));
269 while((begin = silc_gets(line, sizeof(line),
270 buffer->data, buffer->len, begin)) != EOF) {
274 /* Check for bad line */
275 if (silc_check_line(cp))
278 /* Remove tabs and whitespaces from the line */
279 if (strchr(cp, '\t')) {
281 while(strchr(cp + i, '\t')) {
282 *strchr(cp + i, '\t') = ' ';
286 for (i = 0; i < strlen(cp); i++) {
302 /* Remove new line sign */
303 if (strchr(cp, '\n'))
304 *strchr(cp, '\n') = '\0';
306 /* Check for matching sections */
307 for (cptr = silc_config_server_sections; cptr->section; cptr++)
308 if (!strcmp(cp, cptr->section))
311 if (!cptr->section) {
312 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
313 config->filename, linenum, cp);
320 * Start of a configuration line
323 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
325 if (strchr(cp, '\n'))
326 *strchr(cp, '\n') = ':';
329 parse = silc_calloc(1, sizeof(*parse));
331 parse->section = NULL;
335 if (parse->next == NULL) {
336 parse->next = silc_calloc(1, sizeof(*parse->next));
337 parse->next->line = NULL;
338 parse->next->section = NULL;
339 parse->next->next = NULL;
340 parse->next->prev = parse;
348 /* Add the line to parsing structure for further parsing. */
350 parse->section = cptr;
351 parse->line = silc_buffer_alloc(strlen(cp) + 1);
352 parse->linenum = linenum;
353 silc_buffer_pull_tail(parse->line, strlen(cp));
354 silc_buffer_put(parse->line, cp, strlen(cp));
361 /* Set the return_config argument to its first value so that further
362 parsing can be started from the first line. */
363 *return_config = first;
368 /* Parses the lines earlier read from configuration file. The config object
369 must not be initialized, it will be initialized in this function. The
370 parse_config argument is uninitialized automatically during this
373 int silc_config_server_parse_lines(SilcConfigServer config,
374 SilcConfigServerParse parse_config)
376 int ret, check = FALSE;
377 unsigned int checkmask;
379 SilcConfigServerParse pc = parse_config;
382 SILC_LOG_DEBUG(("Parsing configuration lines"));
392 /* Get number of tokens in line */
393 ret = silc_config_check_num_token(line);
394 if (ret != pc->section->maxfields) {
396 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
397 config->filename, pc->linenum, ret,
398 pc->section->maxfields);
403 switch(pc->section->type) {
404 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
406 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
408 /* Get cipher name */
409 ret = silc_config_get_token(line, &config->cipher->alg_name);
413 fprintf(stderr, "%s:%d: Cipher name not defined\n",
414 config->filename, pc->linenum);
418 /* Get module name */
419 config->cipher->sim_name = NULL;
420 ret = silc_config_get_token(line, &config->cipher->sim_name);
424 /* Get block length */
425 ret = silc_config_get_token(line, &tmp);
429 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
430 config->filename, pc->linenum);
433 config->cipher->block_len = atoi(tmp);
437 ret = silc_config_get_token(line, &tmp);
441 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
442 config->filename, pc->linenum);
445 config->cipher->key_len = atoi(tmp);
449 checkmask |= (1L << pc->section->type);
452 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
454 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
457 ret = silc_config_get_token(line, &config->pkcs->alg_name);
461 fprintf(stderr, "%s:%d: PKCS name not defined\n",
462 config->filename, pc->linenum);
467 ret = silc_config_get_token(line, &tmp);
471 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
472 config->filename, pc->linenum);
475 config->pkcs->key_len = atoi(tmp);
479 checkmask |= (1L << pc->section->type);
482 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
484 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
486 /* Get Hash function name */
487 ret = silc_config_get_token(line, &config->hash_func->alg_name);
491 fprintf(stderr, "%s:%d: Hash function name not defined\n",
492 config->filename, pc->linenum);
496 /* Get Hash function module name */
497 config->hash_func->sim_name = NULL;
498 ret = silc_config_get_token(line, &config->hash_func->sim_name);
502 /* Get block length */
503 ret = silc_config_get_token(line, &tmp);
507 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
508 config->filename, pc->linenum);
511 config->hash_func->block_len = atoi(tmp);
514 /* Get hash length */
515 ret = silc_config_get_token(line, &tmp);
519 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
520 config->filename, pc->linenum);
523 config->hash_func->key_len = atoi(tmp);
527 checkmask |= (1L << pc->section->type);
530 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
532 if (!config->server_info)
533 config->server_info = silc_calloc(1, sizeof(*config->server_info));
535 /* Get server name */
536 ret = silc_config_get_token(line, &config->server_info->server_name);
540 /* Server name not defined */
545 ret = silc_config_get_token(line, &config->server_info->server_ip);
549 /* Server IP not defined */
553 /* Get server location */
554 ret = silc_config_get_token(line, &config->server_info->location);
558 /* Get server port */
559 /* XXX: Need port here??? */
560 ret = silc_config_get_token(line, &tmp);
564 /* Port not defined */
567 config->server_info->port = atoi(tmp);
571 checkmask |= (1L << pc->section->type);
574 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
576 if (!config->admin_info)
577 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
579 /* Get server type */
580 ret = silc_config_get_token(line, &config->admin_info->server_type);
584 /* Get admins name */
585 ret = silc_config_get_token(line, &config->admin_info->admin_name);
589 /* Get admins email address */
590 ret = silc_config_get_token(line, &config->admin_info->admin_email);
595 checkmask |= (1L << pc->section->type);
598 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
600 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
603 ret = silc_config_get_token(line, &config->listen_port->host);
608 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
613 ret = silc_config_get_token(line, &tmp);
618 config->listen_port->port = 0;
620 config->listen_port->port = atoi(tmp);
625 checkmask |= (1L << pc->section->type);
628 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
630 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
632 /* Get class number */
633 ret = silc_config_get_token(line, &tmp);
637 /* Class number not defined */
640 config->conn_class->class = atoi(tmp);
643 /* Get ping frequency */
644 ret = silc_config_get_token(line, &tmp);
647 config->conn_class->ping_freq = atoi(tmp);
650 /* Get connect frequency */
651 ret = silc_config_get_token(line, &tmp);
654 config->conn_class->connect_freq = atoi(tmp);
658 ret = silc_config_get_token(line, &tmp);
661 config->conn_class->max_links = atoi(tmp);
665 checkmask |= (1L << pc->section->type);
668 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
670 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
672 /* Get log section type and check it */
673 ret = silc_config_get_token(line, &config->logging->logtype);
677 fprintf(stderr, "%s:%d: Log file section not defined\n",
678 config->filename, pc->linenum);
681 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
682 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
683 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
684 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
685 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
686 config->filename, pc->linenum, config->logging->logtype);
690 /* Get log filename */
691 ret = silc_config_get_token(line, &config->logging->filename);
695 fprintf(stderr, "%s:%d: Log file name not defined\n",
696 config->filename, pc->linenum);
700 /* Get max byte size */
701 ret = silc_config_get_token(line, &tmp);
705 config->logging->maxsize = atoi(tmp);
710 checkmask |= (1L << pc->section->type);
713 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
715 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
718 ret = silc_config_get_token(line, &config->clients->host);
723 config->clients->host = strdup("*");
725 /* Get authentication method */
726 ret = silc_config_get_token(line, &tmp);
730 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
731 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
732 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
733 config->filename, pc->linenum, tmp);
737 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
738 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
740 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
741 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
746 /* Get authentication data */
747 ret = silc_config_get_token(line, &config->clients->auth_data);
752 config->clients->host = strdup("*");
755 ret = silc_config_get_token(line, &tmp);
759 config->clients->port = atoi(tmp);
763 /* Get class number */
764 ret = silc_config_get_token(line, &tmp);
768 config->clients->class = atoi(tmp);
773 checkmask |= (1L << pc->section->type);
776 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
778 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
781 ret = silc_config_get_token(line, &config->servers->host);
786 config->servers->host = strdup("*");
788 /* Get authentication method */
789 ret = silc_config_get_token(line, &tmp);
793 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
794 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
795 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
796 config->filename, pc->linenum, tmp);
800 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
801 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
803 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
804 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
809 /* Get authentication data */
810 ret = silc_config_get_token(line, &config->servers->auth_data);
815 ret = silc_config_get_token(line, &tmp);
819 config->servers->port = atoi(tmp);
824 ret = silc_config_get_token(line, &config->servers->version);
828 /* Get class number */
829 ret = silc_config_get_token(line, &tmp);
833 config->servers->class = atoi(tmp);
838 checkmask |= (1L << pc->section->type);
841 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
843 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
846 ret = silc_config_get_token(line, &config->routers->host);
851 // config->routers->host = strdup("*");
853 /* Get authentication method */
854 ret = silc_config_get_token(line, &tmp);
858 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
859 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
860 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
861 config->filename, pc->linenum, tmp);
865 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
866 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
868 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
869 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
874 /* Get authentication data */
875 ret = silc_config_get_token(line, &config->routers->auth_data);
880 ret = silc_config_get_token(line, &tmp);
884 config->routers->port = atoi(tmp);
889 ret = silc_config_get_token(line, &config->routers->version);
893 /* Get class number */
894 ret = silc_config_get_token(line, &tmp);
898 config->routers->class = atoi(tmp);
903 checkmask |= (1L << pc->section->type);
906 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
908 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
911 ret = silc_config_get_token(line, &config->admins->host);
916 config->admins->host = strdup("*");
918 /* Get authentication method */
919 ret = silc_config_get_token(line, &tmp);
923 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
924 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
925 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
926 config->filename, pc->linenum, tmp);
930 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
931 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
933 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
934 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
939 /* Get authentication data */
940 ret = silc_config_get_token(line, &config->admins->auth_data);
945 ret = silc_config_get_token(line, &config->admins->nickname);
949 /* Get class number */
950 ret = silc_config_get_token(line, &tmp);
954 config->admins->class = atoi(tmp);
959 checkmask |= (1L << pc->section->type);
962 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
963 /* Not implemented yet */
967 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
968 /* Not implemented yet */
972 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
978 /* Check for error */
979 if (check == FALSE) {
980 /* Line could not be parsed */
981 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
987 // silc_free(pc->prev);
994 /* Check that all mandatory sections really were found. If not, the server
995 cannot function and we return error. */
996 ret = silc_config_server_check_sections(checkmask);
1002 /* Before returning all the lists in the config object must be set
1003 to their first values (the last value is first here). */
1004 while (config->cipher && config->cipher->prev)
1005 config->cipher = config->cipher->prev;
1006 while (config->pkcs && config->pkcs->prev)
1007 config->pkcs = config->pkcs->prev;
1008 while (config->hash_func && config->hash_func->prev)
1009 config->hash_func = config->hash_func->prev;
1010 while (config->listen_port && config->listen_port->prev)
1011 config->listen_port = config->listen_port->prev;
1012 while (config->logging && config->logging->prev)
1013 config->logging = config->logging->prev;
1014 while (config->conn_class && config->conn_class->prev)
1015 config->conn_class = config->conn_class->prev;
1016 while (config->clients && config->clients->prev)
1017 config->clients = config->clients->prev;
1018 while (config->servers && config->servers->prev)
1019 config->servers = config->servers->prev;
1020 while (config->routers && config->routers->prev)
1021 config->routers = config->routers->prev;
1023 SILC_LOG_DEBUG(("Done"));
1028 /* This function checks that the mask sent as argument includes all the
1029 sections that are mandatory in SILC server. */
1031 int silc_config_server_check_sections(unsigned int checkmask)
1033 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1037 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1041 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1045 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1050 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1055 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1063 /* Sets log files where log messages is saved by the server. */
1065 void silc_config_server_setlogfiles(SilcConfigServer config)
1067 SilcConfigServerSectionLogging *log;
1068 char *info, *warning, *error, *fatal;
1069 unsigned int info_size, warning_size, error_size, fatal_size;
1071 SILC_LOG_DEBUG(("Setting configured log file names"));
1073 /* Set default files before checking configuration */
1074 info = SILC_LOG_FILE_INFO;
1075 warning = SILC_LOG_FILE_WARNING;
1076 error = SILC_LOG_FILE_ERROR;
1077 fatal = SILC_LOG_FILE_FATAL;
1083 log = config->logging;
1085 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1086 info = log->filename;
1087 info_size = log->maxsize;
1089 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1090 warning = log->filename;
1091 warning_size = log->maxsize;
1093 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1094 error = log->filename;
1095 error_size = log->maxsize;
1097 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1098 fatal = log->filename;
1099 fatal_size = log->maxsize;
1105 silc_log_set_files(info, info_size, warning, warning_size,
1106 error, error_size, fatal, fatal_size);
1109 /* Registers configured ciphers. These can then be allocated by the
1110 server when needed. */
1112 void silc_config_server_register_ciphers(SilcConfigServer config)
1114 SilcConfigServerSectionAlg *alg;
1115 SilcServer server = (SilcServer)config->server;
1117 SILC_LOG_DEBUG(("Registering configured ciphers"));
1119 alg = config->cipher;
1122 if (!alg->sim_name) {
1123 /* Crypto module is supposed to be built in. Nothing to be done
1124 here except to test that the cipher really is built in. */
1125 SilcCipher tmp = NULL;
1127 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1128 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1129 silc_server_stop(server);
1132 silc_cipher_free(tmp);
1136 /* Load (try at least) the crypto SIM module */
1137 SilcCipherObject cipher;
1138 SilcSimContext *sim;
1140 memset(&cipher, 0, sizeof(cipher));
1141 cipher.name = alg->alg_name;
1142 cipher.block_len = alg->block_len;
1143 cipher.key_len = alg->key_len * 8;
1145 sim = silc_sim_alloc();
1146 sim->type = SILC_SIM_CIPHER;
1147 sim->libname = alg->sim_name;
1149 if ((silc_sim_load(sim))) {
1151 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1152 SILC_CIPHER_SIM_SET_KEY));
1153 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1154 cipher.set_key_with_string =
1155 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1156 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1157 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1159 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1160 SILC_CIPHER_SIM_ENCRYPT_CBC));
1161 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1163 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1164 SILC_CIPHER_SIM_DECRYPT_CBC));
1165 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1166 cipher.context_len =
1167 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1168 SILC_CIPHER_SIM_CONTEXT_LEN));
1169 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1171 /* Put the SIM to the table of all SIM's in server */
1172 server->sim = silc_realloc(server->sim,
1173 sizeof(*server->sim) *
1174 (server->sim_count + 1));
1175 server->sim[server->sim_count] = sim;
1176 server->sim_count++;
1178 SILC_LOG_ERROR(("Error configuring ciphers"));
1179 silc_server_stop(server);
1183 /* Register the cipher */
1184 silc_cipher_register(&cipher);
1192 /* Registers configured PKCS's. */
1193 /* XXX: This really doesn't do anything now since we have statically
1194 registered our PKCS's. This should be implemented when PKCS works
1195 as SIM's. This checks now only that the PKCS user requested is
1196 really out there. */
1198 void silc_config_server_register_pkcs(SilcConfigServer config)
1200 SilcConfigServerSectionAlg *alg = config->pkcs;
1201 SilcServer server = (SilcServer)config->server;
1202 SilcPKCS tmp = NULL;
1204 SILC_LOG_DEBUG(("Registering configured PKCS"));
1208 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1209 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1210 silc_server_stop(server);
1219 /* Registers configured hash functions. These can then be allocated by the
1220 server when needed. */
1222 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1224 SilcConfigServerSectionAlg *alg;
1225 SilcServer server = (SilcServer)config->server;
1227 SILC_LOG_DEBUG(("Registering configured hash functions"));
1229 alg = config->hash_func;
1232 if (!alg->sim_name) {
1233 /* Hash module is supposed to be built in. Nothing to be done
1234 here except to test that the hash function really is built in. */
1235 SilcHash tmp = NULL;
1237 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1238 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1239 silc_server_stop(server);
1246 /* Load (try at least) the hash SIM module */
1247 SilcHashObject hash;
1248 SilcSimContext *sim;
1250 memset(&hash, 0, sizeof(hash));
1251 hash.name = alg->alg_name;
1252 hash.block_len = alg->block_len;
1253 hash.hash_len = alg->key_len;
1255 sim = silc_sim_alloc();
1256 sim->type = SILC_SIM_HASH;
1257 sim->libname = alg->sim_name;
1259 if ((silc_sim_load(sim))) {
1261 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1262 SILC_HASH_SIM_INIT));
1263 SILC_LOG_DEBUG(("init=%p", hash.init));
1265 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1266 SILC_HASH_SIM_UPDATE));
1267 SILC_LOG_DEBUG(("update=%p", hash.update));
1269 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1270 SILC_HASH_SIM_FINAL));
1271 SILC_LOG_DEBUG(("final=%p", hash.final));
1273 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1274 SILC_HASH_SIM_CONTEXT_LEN));
1275 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1277 /* Put the SIM to the table of all SIM's in server */
1278 server->sim = silc_realloc(server->sim,
1279 sizeof(*server->sim) *
1280 (server->sim_count + 1));
1281 server->sim[server->sim_count] = sim;
1282 server->sim_count++;
1284 SILC_LOG_ERROR(("Error configuring hash functions"));
1285 silc_server_stop(server);
1289 /* Register the cipher */
1290 silc_hash_register(&hash);
1298 /* Returns client authentication information from server configuration
1299 by host (name or ip). */
1301 SilcConfigServerSectionClientConnection *
1302 silc_config_server_find_client_conn(SilcConfigServer config,
1303 char *host, int port)
1306 SilcConfigServerSectionClientConnection *client = NULL;
1311 if (!config->clients)
1314 client = config->clients;
1316 for (i = 0; client; i++) {
1317 if (silc_string_compare(client->host, host))
1319 client = client->next;
1328 /* Returns server connection info from server configuartion by host
1331 SilcConfigServerSectionServerConnection *
1332 silc_config_server_find_server_conn(SilcConfigServer config,
1333 char *host, int port)
1336 SilcConfigServerSectionServerConnection *serv = NULL;
1341 if (!config->servers)
1344 serv = config->servers;
1345 for (i = 0; serv; i++) {
1346 if (silc_string_compare(serv->host, host))
1357 /* Returns router connection info from server configuartion by
1358 host (name or ip). */
1360 SilcConfigServerSectionServerConnection *
1361 silc_config_server_find_router_conn(SilcConfigServer config,
1362 char *host, int port)
1365 SilcConfigServerSectionServerConnection *serv = NULL;
1370 if (!config->routers)
1373 serv = config->routers;
1374 for (i = 0; serv; i++) {
1375 if (silc_string_compare(serv->host, host))
1386 /* Prints out example configuration file with default built in
1387 configuration values. */
1389 void silc_config_server_print()
1395 # Automatically generated example SILCd configuration file with default\n\
1396 # built in values. Use this as a guide to configure your SILCd configuration\n\
1397 # file for your system. For detailed description of different configuration\n\
1398 # sections refer to silcd(8) manual page.\n\
1413 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1416 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1419 +10.2.1.6:10.2.1.6:1333
1422 +infologfile:silcd.log:10000
1423 #+warninglogfile:/var/log/silcd_warning.log:10000
1424 #+errorlogfile:ERROR.log:10000
1425 #+fatallogfile:/var/log/silcd_error.log:
1432 +10.2.1.199:priikone:333:1
1435 +10.2.1.199:priikone:priikone:1
1445 fprintf(stdout, "%s\n", buf);