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.
22 #include "serverincludes.h"
23 #include "server_internal.h"
26 All possible configuration sections for SILC server.
32 +<Cipher name>:<SIM path>
38 +<PKCS name>:<key length>
44 +<Hash function name>:<SIM path>
48 This section is used to set the server informations.
52 +<Server DNS name>:<Server IP>:<Geographic location>:<Port>
56 This section is used to set the server's administrative information.
60 +<Location>:<Server type>:<Admin's name>:<Admin's email address>
64 This section is used to set ports the server is listenning.
68 +<Local IP/UNIX socket path>:<Remote IP>:<Port>
72 This section is used to set various logging files, their paths
73 and maximum sizes. All the other directives except those defined
74 below are ignored in this section. Log files are purged after they
75 reach the maximum set byte size.
79 +infologfile:<path>:<max byte size>
80 +errorlogfile:<path>:<max byte size>
84 This section is used to define connection classes. These can be
85 used to optimize the server and the connections.
89 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
93 This section is used to define client authentications.
97 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
101 This section is used to define the server's administration
106 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
110 This section is used to define the server connections to this
111 server/router. Only routers can have normal server connections.
112 Normal servers leave this section epmty. The remote server cannot be
113 older than specified Version ID.
117 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
121 This section is used to define the router connections to this
122 server/router. Both normal server and router can have router
123 connections. Normal server usually has only one connection while
124 a router can have multiple. The remote server cannot be older than
125 specified Version ID.
129 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
133 This section is used to deny specific connections to your server. This
134 can be used to deny both clients and servers.
138 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
142 This section is used to set the alternate servers that clients will be
143 redirected to when our server is full.
147 +<Remote address or name>:<Port>
150 SilcConfigServerSection silc_config_server_sections[] = {
152 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
154 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
156 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
158 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
160 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
162 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
164 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
165 { "[ConnectionClass]",
166 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
167 { "[ClientConnection]",
168 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
169 { "[ServerConnection]",
170 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
171 { "[RouterConnection]",
172 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 6 },
173 { "[AdminConnection]",
174 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
175 { "[DenyConnection]",
176 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
177 { "[RedirectClient]",
178 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
180 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
182 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
185 /* Allocates a new configuration object, opens configuration file and
186 parses the file. The parsed data is returned to the newly allocated
187 configuration object. */
189 SilcConfigServer silc_config_server_alloc(char *filename)
191 SilcConfigServer new;
193 SilcConfigServerParse config_parse;
195 SILC_LOG_DEBUG(("Allocating new configuration object"));
197 new = silc_calloc(1, sizeof(*new));
199 fprintf(stderr, "Could not allocate new configuration object");
203 new->filename = filename;
205 /* Open configuration file and parse it */
208 silc_config_open(filename, &buffer);
211 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
213 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
225 /* Free's a configuration object. */
227 void silc_config_server_free(SilcConfigServer config)
230 silc_free(config->filename);
231 silc_free(config->server_info);
232 silc_free(config->admin_info);
233 silc_free(config->listen_port);
234 silc_free(config->conn_class);
235 silc_free(config->clients);
236 silc_free(config->admins);
237 silc_free(config->servers);
238 silc_free(config->routers);
239 silc_free(config->denied);
240 silc_free(config->redirect);
241 silc_free(config->motd);
246 /* Parses the the buffer and returns the parsed lines into return_config
247 argument. The return_config argument doesn't have to be initialized
248 before calling this. It will be initialized during the parsing. The
249 buffer sent as argument can be safely free'd after this function has
250 succesfully returned. */
252 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
253 SilcConfigServerParse *return_config)
256 unsigned int linenum;
257 char line[1024], *cp;
258 SilcConfigServerSection *cptr = NULL;
259 SilcConfigServerParse parse = *return_config, first = NULL;
261 SILC_LOG_DEBUG(("Parsing configuration file"));
265 while((begin = silc_gets(line, sizeof(line),
266 buffer->data, buffer->len, begin)) != EOF) {
270 /* Check for bad line */
271 if (silc_check_line(cp))
274 /* Remove tabs and whitespaces from the line */
275 if (strchr(cp, '\t')) {
277 while(strchr(cp + i, '\t')) {
278 *strchr(cp + i, '\t') = ' ';
282 for (i = 0; i < strlen(cp); i++) {
298 /* Remove new line sign */
299 if (strchr(cp, '\n'))
300 *strchr(cp, '\n') = '\0';
302 /* Check for matching sections */
303 for (cptr = silc_config_server_sections; cptr->section; cptr++)
304 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
307 if (!cptr->section) {
308 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
309 config->filename, linenum, cp);
316 * Start of a configuration line
319 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
321 if (strchr(cp, '\n'))
322 *strchr(cp, '\n') = ':';
325 parse = silc_calloc(1, sizeof(*parse));
327 parse->section = NULL;
331 if (parse->next == NULL) {
332 parse->next = silc_calloc(1, sizeof(*parse->next));
333 parse->next->line = NULL;
334 parse->next->section = NULL;
335 parse->next->next = NULL;
336 parse->next->prev = parse;
344 /* Add the line to parsing structure for further parsing. */
346 parse->section = cptr;
347 parse->line = silc_buffer_alloc(strlen(cp) + 1);
348 parse->linenum = linenum;
349 silc_buffer_pull_tail(parse->line, strlen(cp));
350 silc_buffer_put(parse->line, cp, strlen(cp));
357 /* Set the return_config argument to its first value so that further
358 parsing can be started from the first line. */
359 *return_config = first;
364 /* Parses the lines earlier read from configuration file. The config object
365 must not be initialized, it will be initialized in this function. The
366 parse_config argument is uninitialized automatically during this
369 int silc_config_server_parse_lines(SilcConfigServer config,
370 SilcConfigServerParse parse_config)
372 int ret, check = FALSE;
373 unsigned int checkmask;
375 SilcConfigServerParse pc = parse_config;
378 SILC_LOG_DEBUG(("Parsing configuration lines"));
388 /* Get number of tokens in line */
389 ret = silc_config_check_num_token(line);
390 if (ret != pc->section->maxfields) {
392 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
393 config->filename, pc->linenum, ret,
394 pc->section->maxfields);
399 switch(pc->section->type) {
400 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
402 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
404 /* Get cipher name */
405 ret = silc_config_get_token(line, &config->cipher->alg_name);
409 fprintf(stderr, "%s:%d: Cipher name not defined\n",
410 config->filename, pc->linenum);
414 /* Get module name */
415 config->cipher->sim_name = NULL;
416 ret = silc_config_get_token(line, &config->cipher->sim_name);
420 /* Get block length */
421 ret = silc_config_get_token(line, &tmp);
425 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
426 config->filename, pc->linenum);
429 config->cipher->block_len = atoi(tmp);
433 ret = silc_config_get_token(line, &tmp);
437 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
438 config->filename, pc->linenum);
441 config->cipher->key_len = atoi(tmp);
445 checkmask |= (1L << pc->section->type);
448 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
450 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
453 ret = silc_config_get_token(line, &config->pkcs->alg_name);
457 fprintf(stderr, "%s:%d: PKCS name not defined\n",
458 config->filename, pc->linenum);
463 ret = silc_config_get_token(line, &tmp);
467 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
468 config->filename, pc->linenum);
471 config->pkcs->key_len = atoi(tmp);
475 checkmask |= (1L << pc->section->type);
478 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
480 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
482 /* Get Hash function name */
483 ret = silc_config_get_token(line, &config->hash_func->alg_name);
487 fprintf(stderr, "%s:%d: Hash function name not defined\n",
488 config->filename, pc->linenum);
492 /* Get Hash function module name */
493 config->hash_func->sim_name = NULL;
494 ret = silc_config_get_token(line, &config->hash_func->sim_name);
498 /* Get block length */
499 ret = silc_config_get_token(line, &tmp);
503 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
504 config->filename, pc->linenum);
507 config->hash_func->block_len = atoi(tmp);
510 /* Get hash length */
511 ret = silc_config_get_token(line, &tmp);
515 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
516 config->filename, pc->linenum);
519 config->hash_func->key_len = atoi(tmp);
523 checkmask |= (1L << pc->section->type);
526 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
528 if (!config->server_info)
529 config->server_info = silc_calloc(1, sizeof(*config->server_info));
531 /* Get server name */
532 ret = silc_config_get_token(line, &config->server_info->server_name);
536 /* Server name not defined */
541 ret = silc_config_get_token(line, &config->server_info->server_ip);
545 /* Server IP not defined */
549 /* Get server location */
550 ret = silc_config_get_token(line, &config->server_info->location);
554 /* Get server port */
555 /* XXX: Need port here??? */
556 ret = silc_config_get_token(line, &tmp);
560 /* Port not defined */
563 config->server_info->port = atoi(tmp);
567 checkmask |= (1L << pc->section->type);
570 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
572 if (!config->admin_info)
573 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
576 ret = silc_config_get_token(line, &config->admin_info->location);
580 /* Get server type */
581 ret = silc_config_get_token(line, &config->admin_info->server_type);
585 /* Get admins name */
586 ret = silc_config_get_token(line, &config->admin_info->admin_name);
590 /* Get admins email address */
591 ret = silc_config_get_token(line, &config->admin_info->admin_email);
596 checkmask |= (1L << pc->section->type);
599 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
601 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
604 ret = silc_config_get_token(line, &config->listen_port->host);
609 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
614 ret = silc_config_get_token(line, &tmp);
619 config->listen_port->port = 0;
621 config->listen_port->port = atoi(tmp);
626 checkmask |= (1L << pc->section->type);
629 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
631 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
633 /* Get class number */
634 ret = silc_config_get_token(line, &tmp);
638 /* Class number not defined */
641 config->conn_class->class = atoi(tmp);
644 /* Get ping frequency */
645 ret = silc_config_get_token(line, &tmp);
648 config->conn_class->ping_freq = atoi(tmp);
651 /* Get connect frequency */
652 ret = silc_config_get_token(line, &tmp);
655 config->conn_class->connect_freq = atoi(tmp);
659 ret = silc_config_get_token(line, &tmp);
662 config->conn_class->max_links = atoi(tmp);
666 checkmask |= (1L << pc->section->type);
669 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
671 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
673 /* Get log section type and check it */
674 ret = silc_config_get_token(line, &config->logging->logtype);
678 fprintf(stderr, "%s:%d: Log file section not defined\n",
679 config->filename, pc->linenum);
682 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
683 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
684 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
685 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
686 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
687 config->filename, pc->linenum, config->logging->logtype);
691 /* Get log filename */
692 ret = silc_config_get_token(line, &config->logging->filename);
696 fprintf(stderr, "%s:%d: Log file name not defined\n",
697 config->filename, pc->linenum);
701 /* Get max byte size */
702 ret = silc_config_get_token(line, &tmp);
706 config->logging->maxsize = atoi(tmp);
711 checkmask |= (1L << pc->section->type);
714 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
716 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
719 ret = silc_config_get_token(line, &config->clients->host);
724 config->clients->host = strdup("*");
726 /* Get authentication method */
727 ret = silc_config_get_token(line, &tmp);
731 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
732 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
733 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
734 config->filename, pc->linenum, tmp);
738 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
739 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
741 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
742 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
747 /* Get authentication data */
748 ret = silc_config_get_token(line, &config->clients->auth_data);
753 config->clients->host = strdup("*");
756 ret = silc_config_get_token(line, &tmp);
760 config->clients->port = atoi(tmp);
764 /* Get class number */
765 ret = silc_config_get_token(line, &tmp);
769 config->clients->class = atoi(tmp);
774 checkmask |= (1L << pc->section->type);
777 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
779 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
782 ret = silc_config_get_token(line, &config->servers->host);
787 config->servers->host = strdup("*");
789 /* Get authentication method */
790 ret = silc_config_get_token(line, &tmp);
794 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
795 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
796 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
797 config->filename, pc->linenum, tmp);
801 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
802 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
804 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
805 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
810 /* Get authentication data */
811 ret = silc_config_get_token(line, &config->servers->auth_data);
816 ret = silc_config_get_token(line, &tmp);
820 config->servers->port = atoi(tmp);
825 ret = silc_config_get_token(line, &config->servers->version);
829 /* Get class number */
830 ret = silc_config_get_token(line, &tmp);
834 config->servers->class = atoi(tmp);
839 checkmask |= (1L << pc->section->type);
842 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
844 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
847 ret = silc_config_get_token(line, &config->routers->host);
852 // config->routers->host = strdup("*");
854 /* Get authentication method */
855 ret = silc_config_get_token(line, &tmp);
859 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
860 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
861 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
862 config->filename, pc->linenum, tmp);
866 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
867 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
869 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
870 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
875 /* Get authentication data */
876 ret = silc_config_get_token(line, &config->routers->auth_data);
881 ret = silc_config_get_token(line, &tmp);
885 config->routers->port = atoi(tmp);
890 ret = silc_config_get_token(line, &config->routers->version);
894 /* Get class number */
895 ret = silc_config_get_token(line, &tmp);
899 config->routers->class = atoi(tmp);
904 checkmask |= (1L << pc->section->type);
907 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
909 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
912 ret = silc_config_get_token(line, &config->admins->host);
917 config->admins->host = strdup("*");
919 /* Get authentication method */
920 ret = silc_config_get_token(line, &tmp);
924 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
925 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
926 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
927 config->filename, pc->linenum, tmp);
931 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
932 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
934 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
935 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
940 /* Get authentication data */
941 ret = silc_config_get_token(line, &config->admins->auth_data);
946 ret = silc_config_get_token(line, &config->admins->nickname);
950 /* Get class number */
951 ret = silc_config_get_token(line, &tmp);
955 config->admins->class = atoi(tmp);
960 checkmask |= (1L << pc->section->type);
963 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
964 /* Not implemented yet */
968 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
969 /* Not implemented yet */
973 case SILC_CONFIG_SERVER_SECTION_TYPE_MOTD:
976 config->motd = silc_calloc(1, sizeof(*config->motd));
979 ret = silc_config_get_token(line, &config->motd->motd_file);
984 checkmask |= (1L << pc->section->type);
987 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
993 /* Check for error */
994 if (check == FALSE) {
995 /* Line could not be parsed */
996 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
1002 // silc_free(pc->prev);
1009 /* Check that all mandatory sections really were found. If not, the server
1010 cannot function and we return error. */
1011 ret = silc_config_server_check_sections(checkmask);
1017 /* Before returning all the lists in the config object must be set
1018 to their first values (the last value is first here). */
1019 while (config->cipher && config->cipher->prev)
1020 config->cipher = config->cipher->prev;
1021 while (config->pkcs && config->pkcs->prev)
1022 config->pkcs = config->pkcs->prev;
1023 while (config->hash_func && config->hash_func->prev)
1024 config->hash_func = config->hash_func->prev;
1025 while (config->listen_port && config->listen_port->prev)
1026 config->listen_port = config->listen_port->prev;
1027 while (config->logging && config->logging->prev)
1028 config->logging = config->logging->prev;
1029 while (config->conn_class && config->conn_class->prev)
1030 config->conn_class = config->conn_class->prev;
1031 while (config->clients && config->clients->prev)
1032 config->clients = config->clients->prev;
1033 while (config->servers && config->servers->prev)
1034 config->servers = config->servers->prev;
1035 while (config->routers && config->routers->prev)
1036 config->routers = config->routers->prev;
1038 SILC_LOG_DEBUG(("Done"));
1043 /* This function checks that the mask sent as argument includes all the
1044 sections that are mandatory in SILC server. */
1046 int silc_config_server_check_sections(unsigned int checkmask)
1048 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1052 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1056 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1060 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1065 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1070 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1078 /* Sets log files where log messages is saved by the server. */
1080 void silc_config_server_setlogfiles(SilcConfigServer config)
1082 SilcConfigServerSectionLogging *log;
1083 char *info, *warning, *error, *fatal;
1084 unsigned int info_size, warning_size, error_size, fatal_size;
1086 SILC_LOG_DEBUG(("Setting configured log file names"));
1088 /* Set default files before checking configuration */
1089 info = SILC_LOG_FILE_INFO;
1090 warning = SILC_LOG_FILE_WARNING;
1091 error = SILC_LOG_FILE_ERROR;
1092 fatal = SILC_LOG_FILE_FATAL;
1098 log = config->logging;
1100 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1101 info = log->filename;
1102 info_size = log->maxsize;
1104 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1105 warning = log->filename;
1106 warning_size = log->maxsize;
1108 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1109 error = log->filename;
1110 error_size = log->maxsize;
1112 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1113 fatal = log->filename;
1114 fatal_size = log->maxsize;
1120 silc_log_set_files(info, info_size, warning, warning_size,
1121 error, error_size, fatal, fatal_size);
1124 /* Registers configured ciphers. These can then be allocated by the
1125 server when needed. */
1127 void silc_config_server_register_ciphers(SilcConfigServer config)
1129 SilcConfigServerSectionAlg *alg;
1130 SilcServer server = (SilcServer)config->server;
1132 SILC_LOG_DEBUG(("Registering configured ciphers"));
1134 alg = config->cipher;
1137 if (!alg->sim_name) {
1138 /* Crypto module is supposed to be built in. Nothing to be done
1139 here except to test that the cipher really is built in. */
1140 SilcCipher tmp = NULL;
1142 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1143 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1144 silc_server_stop(server);
1147 silc_cipher_free(tmp);
1151 /* Load (try at least) the crypto SIM module */
1152 SilcCipherObject cipher;
1153 SilcSimContext *sim;
1155 memset(&cipher, 0, sizeof(cipher));
1156 cipher.name = alg->alg_name;
1157 cipher.block_len = alg->block_len;
1158 cipher.key_len = alg->key_len * 8;
1160 sim = silc_sim_alloc();
1161 sim->type = SILC_SIM_CIPHER;
1162 sim->libname = alg->sim_name;
1164 if ((silc_sim_load(sim))) {
1166 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1167 SILC_CIPHER_SIM_SET_KEY));
1168 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1169 cipher.set_key_with_string =
1170 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1171 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1172 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1174 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1175 SILC_CIPHER_SIM_ENCRYPT_CBC));
1176 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1178 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1179 SILC_CIPHER_SIM_DECRYPT_CBC));
1180 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1181 cipher.context_len =
1182 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1183 SILC_CIPHER_SIM_CONTEXT_LEN));
1184 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1186 /* Put the SIM to the list of all SIM's in server */
1187 silc_dlist_add(server->sim, sim);
1189 SILC_LOG_ERROR(("Error configuring ciphers"));
1190 silc_server_stop(server);
1194 /* Register the cipher */
1195 silc_cipher_register(&cipher);
1203 /* Registers configured PKCS's. */
1204 /* XXX: This really doesn't do anything now since we have statically
1205 registered our PKCS's. This should be implemented when PKCS works
1206 as SIM's. This checks now only that the PKCS user requested is
1207 really out there. */
1209 void silc_config_server_register_pkcs(SilcConfigServer config)
1211 SilcConfigServerSectionAlg *alg = config->pkcs;
1212 SilcServer server = (SilcServer)config->server;
1213 SilcPKCS tmp = NULL;
1215 SILC_LOG_DEBUG(("Registering configured PKCS"));
1219 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1220 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1221 silc_server_stop(server);
1230 /* Registers configured hash functions. These can then be allocated by the
1231 server when needed. */
1233 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1235 SilcConfigServerSectionAlg *alg;
1236 SilcServer server = (SilcServer)config->server;
1238 SILC_LOG_DEBUG(("Registering configured hash functions"));
1240 alg = config->hash_func;
1243 if (!alg->sim_name) {
1244 /* Hash module is supposed to be built in. Nothing to be done
1245 here except to test that the hash function really is built in. */
1246 SilcHash tmp = NULL;
1248 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1249 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1250 silc_server_stop(server);
1257 /* Load (try at least) the hash SIM module */
1258 SilcHashObject hash;
1259 SilcSimContext *sim;
1261 memset(&hash, 0, sizeof(hash));
1262 hash.name = alg->alg_name;
1263 hash.block_len = alg->block_len;
1264 hash.hash_len = alg->key_len;
1266 sim = silc_sim_alloc();
1267 sim->type = SILC_SIM_HASH;
1268 sim->libname = alg->sim_name;
1270 if ((silc_sim_load(sim))) {
1272 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1273 SILC_HASH_SIM_INIT));
1274 SILC_LOG_DEBUG(("init=%p", hash.init));
1276 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1277 SILC_HASH_SIM_UPDATE));
1278 SILC_LOG_DEBUG(("update=%p", hash.update));
1280 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1281 SILC_HASH_SIM_FINAL));
1282 SILC_LOG_DEBUG(("final=%p", hash.final));
1284 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1285 SILC_HASH_SIM_CONTEXT_LEN));
1286 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1288 /* Put the SIM to the table of all SIM's in server */
1289 silc_dlist_add(server->sim, sim);
1291 SILC_LOG_ERROR(("Error configuring hash functions"));
1292 silc_server_stop(server);
1296 /* Register the cipher */
1297 silc_hash_register(&hash);
1305 /* Returns client authentication information from server configuration
1306 by host (name or ip). */
1308 SilcConfigServerSectionClientConnection *
1309 silc_config_server_find_client_conn(SilcConfigServer config,
1310 char *host, int port)
1313 SilcConfigServerSectionClientConnection *client = NULL;
1318 if (!config->clients)
1321 client = config->clients;
1323 for (i = 0; client; i++) {
1324 if (silc_string_compare(client->host, host))
1326 client = client->next;
1335 /* Returns server connection info from server configuartion by host
1338 SilcConfigServerSectionServerConnection *
1339 silc_config_server_find_server_conn(SilcConfigServer config,
1340 char *host, int port)
1343 SilcConfigServerSectionServerConnection *serv = NULL;
1348 if (!config->servers)
1351 serv = config->servers;
1352 for (i = 0; serv; i++) {
1353 if (silc_string_compare(serv->host, host))
1364 /* Returns router connection info from server configuartion by
1365 host (name or ip). */
1367 SilcConfigServerSectionServerConnection *
1368 silc_config_server_find_router_conn(SilcConfigServer config,
1369 char *host, int port)
1372 SilcConfigServerSectionServerConnection *serv = NULL;
1377 if (!config->routers)
1380 serv = config->routers;
1381 for (i = 0; serv; i++) {
1382 if (silc_string_compare(serv->host, host))
1393 /* Prints out example configuration file with default built in
1394 configuration values. */
1396 void silc_config_server_print()
1402 # Automatically generated example SILCd configuration file with default\n\
1403 # built in values. Use this as a guide to configure your SILCd configuration\n\
1404 # file for your system. For detailed description of different configuration\n\
1405 # sections refer to silcd(8) manual page.\n\
1420 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1423 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1426 +10.2.1.6:10.2.1.6:1333
1429 +infologfile:silcd.log:10000
1430 #+warninglogfile:/var/log/silcd_warning.log:10000
1431 #+errorlogfile:ERROR.log:10000
1432 #+fatallogfile:/var/log/silcd_error.log:
1439 +10.2.1.199:priikone:333:1
1442 +10.2.1.199:priikone:priikone:1
1452 fprintf(stdout, "%s\n", buf);