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.2 2000/07/05 06:14:01 priikone
24 * Global costemic changes.
26 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
27 * Imported from internal CVS/Added Log headers.
32 #include "serverincludes.h"
33 #include "server_internal.h"
36 All possible configuration sections for SILC server.
42 +<Cipher name>:<SIM path>
48 +<PKCS name>:<key length>
54 +<Hash function name>:<SIM path>
58 This section is used to set the server informations.
62 +<Server DNS name>:<Server IP>:<Geographic location>:<Port>
66 This section is used to set the server's administrative information.
70 +<Location>:<Server type>:<Admin's name>:<Admin's email address>
74 This section is used to set ports the server is listenning.
78 +<Local IP/UNIX socket path>:<Remote IP>:<Port>
82 This section is used to set various logging files, their paths
83 and maximum sizes. All the other directives except those defined
84 below are ignored in this section. Log files are purged after they
85 reach the maximum set byte size.
89 +infologfile:<path>:<max byte size>
90 +errorlogfile:<path>:<max byte size>
94 This section is used to define connection classes. These can be
95 used to optimize the server and the connections.
99 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
103 This section is used to define client authentications.
107 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
111 This section is used to define the server's administration
116 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
120 This section is used to define the server connections to this
121 server/router. Only routers can have normal server connections.
122 Normal servers leave this section epmty. The remote server cannot be
123 older than specified Version ID.
127 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
131 This section is used to define the router connections to this
132 server/router. Both normal server and router can have router
133 connections. Normal server usually has only one connection while
134 a router can have multiple. The remote server cannot be older than
135 specified Version ID.
139 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
143 This section is used to deny specific connections to your server. This
144 can be used to deny both clients and servers.
148 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
152 This section is used to set the alternate servers that clients will be
153 redirected to when our server is full.
157 +<Remote address or name>:<Port>
160 SilcConfigServerSection silc_config_server_sections[] = {
162 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
164 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
166 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
168 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
170 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
172 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
174 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
175 { "[ConnectionClass]",
176 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
177 { "[ClientConnection]",
178 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
179 { "[ServerConnection]",
180 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
181 { "[RouterConnection]",
182 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 6 },
183 { "[AdminConnection]",
184 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
185 { "[DenyConnection]",
186 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
187 { "[RedirectClient]",
188 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
190 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
193 /* Allocates a new configuration object, opens configuration file and
194 parses the file. The parsed data is returned to the newly allocated
195 configuration object. */
197 SilcConfigServer silc_config_server_alloc(char *filename)
199 SilcConfigServer new;
201 SilcConfigServerParse config_parse;
203 SILC_LOG_DEBUG(("Allocating new configuration object"));
205 new = silc_calloc(1, sizeof(*new));
207 fprintf(stderr, "Could not allocate new configuration object");
211 new->filename = filename;
213 /* Open configuration file and parse it */
216 silc_config_open(filename, &buffer);
219 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
221 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
233 /* Free's a configuration object. */
235 void silc_config_server_free(SilcConfigServer config)
238 silc_free(config->filename);
239 silc_free(config->server_info);
240 silc_free(config->admin_info);
241 silc_free(config->listen_port);
242 silc_free(config->conn_class);
243 silc_free(config->clients);
244 silc_free(config->admins);
245 silc_free(config->servers);
246 silc_free(config->routers);
247 silc_free(config->denied);
248 silc_free(config->redirect);
253 /* Parses the the buffer and returns the parsed lines into return_config
254 argument. The return_config argument doesn't have to be initialized
255 before calling this. It will be initialized during the parsing. The
256 buffer sent as argument can be safely free'd after this function has
257 succesfully returned. */
259 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
260 SilcConfigServerParse *return_config)
263 unsigned int linenum;
264 char line[1024], *cp;
265 SilcConfigServerSection *cptr = NULL;
266 SilcConfigServerParse parse = *return_config, first = NULL;
268 SILC_LOG_DEBUG(("Parsing configuration file"));
272 while((begin = silc_gets(line, sizeof(line),
273 buffer->data, buffer->len, begin)) != EOF) {
277 /* Check for bad line */
278 if (silc_check_line(cp))
281 /* Remove tabs and whitespaces from the line */
282 if (strchr(cp, '\t')) {
284 while(strchr(cp + i, '\t')) {
285 *strchr(cp + i, '\t') = ' ';
289 for (i = 0; i < strlen(cp); i++) {
305 /* Remove new line sign */
306 if (strchr(cp, '\n'))
307 *strchr(cp, '\n') = '\0';
309 /* Check for matching sections */
310 for (cptr = silc_config_server_sections; cptr->section; cptr++)
311 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
314 if (!cptr->section) {
315 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
316 config->filename, linenum, cp);
323 * Start of a configuration line
326 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
328 if (strchr(cp, '\n'))
329 *strchr(cp, '\n') = ':';
332 parse = silc_calloc(1, sizeof(*parse));
334 parse->section = NULL;
338 if (parse->next == NULL) {
339 parse->next = silc_calloc(1, sizeof(*parse->next));
340 parse->next->line = NULL;
341 parse->next->section = NULL;
342 parse->next->next = NULL;
343 parse->next->prev = parse;
351 /* Add the line to parsing structure for further parsing. */
353 parse->section = cptr;
354 parse->line = silc_buffer_alloc(strlen(cp) + 1);
355 parse->linenum = linenum;
356 silc_buffer_pull_tail(parse->line, strlen(cp));
357 silc_buffer_put(parse->line, cp, strlen(cp));
364 /* Set the return_config argument to its first value so that further
365 parsing can be started from the first line. */
366 *return_config = first;
371 /* Parses the lines earlier read from configuration file. The config object
372 must not be initialized, it will be initialized in this function. The
373 parse_config argument is uninitialized automatically during this
376 int silc_config_server_parse_lines(SilcConfigServer config,
377 SilcConfigServerParse parse_config)
379 int ret, check = FALSE;
380 unsigned int checkmask;
382 SilcConfigServerParse pc = parse_config;
385 SILC_LOG_DEBUG(("Parsing configuration lines"));
395 /* Get number of tokens in line */
396 ret = silc_config_check_num_token(line);
397 if (ret != pc->section->maxfields) {
399 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
400 config->filename, pc->linenum, ret,
401 pc->section->maxfields);
406 switch(pc->section->type) {
407 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
409 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
411 /* Get cipher name */
412 ret = silc_config_get_token(line, &config->cipher->alg_name);
416 fprintf(stderr, "%s:%d: Cipher name not defined\n",
417 config->filename, pc->linenum);
421 /* Get module name */
422 config->cipher->sim_name = NULL;
423 ret = silc_config_get_token(line, &config->cipher->sim_name);
427 /* Get block length */
428 ret = silc_config_get_token(line, &tmp);
432 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
433 config->filename, pc->linenum);
436 config->cipher->block_len = atoi(tmp);
440 ret = silc_config_get_token(line, &tmp);
444 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
445 config->filename, pc->linenum);
448 config->cipher->key_len = atoi(tmp);
452 checkmask |= (1L << pc->section->type);
455 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
457 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
460 ret = silc_config_get_token(line, &config->pkcs->alg_name);
464 fprintf(stderr, "%s:%d: PKCS name not defined\n",
465 config->filename, pc->linenum);
470 ret = silc_config_get_token(line, &tmp);
474 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
475 config->filename, pc->linenum);
478 config->pkcs->key_len = atoi(tmp);
482 checkmask |= (1L << pc->section->type);
485 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
487 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
489 /* Get Hash function name */
490 ret = silc_config_get_token(line, &config->hash_func->alg_name);
494 fprintf(stderr, "%s:%d: Hash function name not defined\n",
495 config->filename, pc->linenum);
499 /* Get Hash function module name */
500 config->hash_func->sim_name = NULL;
501 ret = silc_config_get_token(line, &config->hash_func->sim_name);
505 /* Get block length */
506 ret = silc_config_get_token(line, &tmp);
510 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
511 config->filename, pc->linenum);
514 config->hash_func->block_len = atoi(tmp);
517 /* Get hash length */
518 ret = silc_config_get_token(line, &tmp);
522 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
523 config->filename, pc->linenum);
526 config->hash_func->key_len = atoi(tmp);
530 checkmask |= (1L << pc->section->type);
533 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
535 if (!config->server_info)
536 config->server_info = silc_calloc(1, sizeof(*config->server_info));
538 /* Get server name */
539 ret = silc_config_get_token(line, &config->server_info->server_name);
543 /* Server name not defined */
548 ret = silc_config_get_token(line, &config->server_info->server_ip);
552 /* Server IP not defined */
556 /* Get server location */
557 ret = silc_config_get_token(line, &config->server_info->location);
561 /* Get server port */
562 /* XXX: Need port here??? */
563 ret = silc_config_get_token(line, &tmp);
567 /* Port not defined */
570 config->server_info->port = atoi(tmp);
574 checkmask |= (1L << pc->section->type);
577 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
579 if (!config->admin_info)
580 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
582 /* Get server type */
583 ret = silc_config_get_token(line, &config->admin_info->server_type);
587 /* Get admins name */
588 ret = silc_config_get_token(line, &config->admin_info->admin_name);
592 /* Get admins email address */
593 ret = silc_config_get_token(line, &config->admin_info->admin_email);
598 checkmask |= (1L << pc->section->type);
601 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
603 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
606 ret = silc_config_get_token(line, &config->listen_port->host);
611 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
616 ret = silc_config_get_token(line, &tmp);
621 config->listen_port->port = 0;
623 config->listen_port->port = atoi(tmp);
628 checkmask |= (1L << pc->section->type);
631 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
633 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
635 /* Get class number */
636 ret = silc_config_get_token(line, &tmp);
640 /* Class number not defined */
643 config->conn_class->class = atoi(tmp);
646 /* Get ping frequency */
647 ret = silc_config_get_token(line, &tmp);
650 config->conn_class->ping_freq = atoi(tmp);
653 /* Get connect frequency */
654 ret = silc_config_get_token(line, &tmp);
657 config->conn_class->connect_freq = atoi(tmp);
661 ret = silc_config_get_token(line, &tmp);
664 config->conn_class->max_links = atoi(tmp);
668 checkmask |= (1L << pc->section->type);
671 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
673 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
675 /* Get log section type and check it */
676 ret = silc_config_get_token(line, &config->logging->logtype);
680 fprintf(stderr, "%s:%d: Log file section not defined\n",
681 config->filename, pc->linenum);
684 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
685 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
686 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
687 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
688 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
689 config->filename, pc->linenum, config->logging->logtype);
693 /* Get log filename */
694 ret = silc_config_get_token(line, &config->logging->filename);
698 fprintf(stderr, "%s:%d: Log file name not defined\n",
699 config->filename, pc->linenum);
703 /* Get max byte size */
704 ret = silc_config_get_token(line, &tmp);
708 config->logging->maxsize = atoi(tmp);
713 checkmask |= (1L << pc->section->type);
716 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
718 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
721 ret = silc_config_get_token(line, &config->clients->host);
726 config->clients->host = strdup("*");
728 /* Get authentication method */
729 ret = silc_config_get_token(line, &tmp);
733 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
734 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
735 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
736 config->filename, pc->linenum, tmp);
740 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
741 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
743 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
744 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
749 /* Get authentication data */
750 ret = silc_config_get_token(line, &config->clients->auth_data);
755 config->clients->host = strdup("*");
758 ret = silc_config_get_token(line, &tmp);
762 config->clients->port = atoi(tmp);
766 /* Get class number */
767 ret = silc_config_get_token(line, &tmp);
771 config->clients->class = atoi(tmp);
776 checkmask |= (1L << pc->section->type);
779 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
781 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
784 ret = silc_config_get_token(line, &config->servers->host);
789 config->servers->host = strdup("*");
791 /* Get authentication method */
792 ret = silc_config_get_token(line, &tmp);
796 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
797 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
798 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
799 config->filename, pc->linenum, tmp);
803 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
804 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
806 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
807 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
812 /* Get authentication data */
813 ret = silc_config_get_token(line, &config->servers->auth_data);
818 ret = silc_config_get_token(line, &tmp);
822 config->servers->port = atoi(tmp);
827 ret = silc_config_get_token(line, &config->servers->version);
831 /* Get class number */
832 ret = silc_config_get_token(line, &tmp);
836 config->servers->class = atoi(tmp);
841 checkmask |= (1L << pc->section->type);
844 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
846 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
849 ret = silc_config_get_token(line, &config->routers->host);
854 // config->routers->host = strdup("*");
856 /* Get authentication method */
857 ret = silc_config_get_token(line, &tmp);
861 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
862 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
863 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
864 config->filename, pc->linenum, tmp);
868 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
869 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
871 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
872 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
877 /* Get authentication data */
878 ret = silc_config_get_token(line, &config->routers->auth_data);
883 ret = silc_config_get_token(line, &tmp);
887 config->routers->port = atoi(tmp);
892 ret = silc_config_get_token(line, &config->routers->version);
896 /* Get class number */
897 ret = silc_config_get_token(line, &tmp);
901 config->routers->class = atoi(tmp);
906 checkmask |= (1L << pc->section->type);
909 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
911 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
914 ret = silc_config_get_token(line, &config->admins->host);
919 config->admins->host = strdup("*");
921 /* Get authentication method */
922 ret = silc_config_get_token(line, &tmp);
926 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
927 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
928 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
929 config->filename, pc->linenum, tmp);
933 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
934 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
936 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
937 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
942 /* Get authentication data */
943 ret = silc_config_get_token(line, &config->admins->auth_data);
948 ret = silc_config_get_token(line, &config->admins->nickname);
952 /* Get class number */
953 ret = silc_config_get_token(line, &tmp);
957 config->admins->class = atoi(tmp);
962 checkmask |= (1L << pc->section->type);
965 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
966 /* Not implemented yet */
970 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
971 /* Not implemented yet */
975 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
981 /* Check for error */
982 if (check == FALSE) {
983 /* Line could not be parsed */
984 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
990 // silc_free(pc->prev);
997 /* Check that all mandatory sections really were found. If not, the server
998 cannot function and we return error. */
999 ret = silc_config_server_check_sections(checkmask);
1005 /* Before returning all the lists in the config object must be set
1006 to their first values (the last value is first here). */
1007 while (config->cipher && config->cipher->prev)
1008 config->cipher = config->cipher->prev;
1009 while (config->pkcs && config->pkcs->prev)
1010 config->pkcs = config->pkcs->prev;
1011 while (config->hash_func && config->hash_func->prev)
1012 config->hash_func = config->hash_func->prev;
1013 while (config->listen_port && config->listen_port->prev)
1014 config->listen_port = config->listen_port->prev;
1015 while (config->logging && config->logging->prev)
1016 config->logging = config->logging->prev;
1017 while (config->conn_class && config->conn_class->prev)
1018 config->conn_class = config->conn_class->prev;
1019 while (config->clients && config->clients->prev)
1020 config->clients = config->clients->prev;
1021 while (config->servers && config->servers->prev)
1022 config->servers = config->servers->prev;
1023 while (config->routers && config->routers->prev)
1024 config->routers = config->routers->prev;
1026 SILC_LOG_DEBUG(("Done"));
1031 /* This function checks that the mask sent as argument includes all the
1032 sections that are mandatory in SILC server. */
1034 int silc_config_server_check_sections(unsigned int checkmask)
1036 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1040 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1044 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1048 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1053 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1058 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1066 /* Sets log files where log messages is saved by the server. */
1068 void silc_config_server_setlogfiles(SilcConfigServer config)
1070 SilcConfigServerSectionLogging *log;
1071 char *info, *warning, *error, *fatal;
1072 unsigned int info_size, warning_size, error_size, fatal_size;
1074 SILC_LOG_DEBUG(("Setting configured log file names"));
1076 /* Set default files before checking configuration */
1077 info = SILC_LOG_FILE_INFO;
1078 warning = SILC_LOG_FILE_WARNING;
1079 error = SILC_LOG_FILE_ERROR;
1080 fatal = SILC_LOG_FILE_FATAL;
1086 log = config->logging;
1088 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1089 info = log->filename;
1090 info_size = log->maxsize;
1092 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1093 warning = log->filename;
1094 warning_size = log->maxsize;
1096 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1097 error = log->filename;
1098 error_size = log->maxsize;
1100 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1101 fatal = log->filename;
1102 fatal_size = log->maxsize;
1108 silc_log_set_files(info, info_size, warning, warning_size,
1109 error, error_size, fatal, fatal_size);
1112 /* Registers configured ciphers. These can then be allocated by the
1113 server when needed. */
1115 void silc_config_server_register_ciphers(SilcConfigServer config)
1117 SilcConfigServerSectionAlg *alg;
1118 SilcServer server = (SilcServer)config->server;
1120 SILC_LOG_DEBUG(("Registering configured ciphers"));
1122 alg = config->cipher;
1125 if (!alg->sim_name) {
1126 /* Crypto module is supposed to be built in. Nothing to be done
1127 here except to test that the cipher really is built in. */
1128 SilcCipher tmp = NULL;
1130 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1131 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1132 silc_server_stop(server);
1135 silc_cipher_free(tmp);
1139 /* Load (try at least) the crypto SIM module */
1140 SilcCipherObject cipher;
1141 SilcSimContext *sim;
1143 memset(&cipher, 0, sizeof(cipher));
1144 cipher.name = alg->alg_name;
1145 cipher.block_len = alg->block_len;
1146 cipher.key_len = alg->key_len * 8;
1148 sim = silc_sim_alloc();
1149 sim->type = SILC_SIM_CIPHER;
1150 sim->libname = alg->sim_name;
1152 if ((silc_sim_load(sim))) {
1154 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1155 SILC_CIPHER_SIM_SET_KEY));
1156 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1157 cipher.set_key_with_string =
1158 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1159 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1160 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1162 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1163 SILC_CIPHER_SIM_ENCRYPT_CBC));
1164 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1166 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1167 SILC_CIPHER_SIM_DECRYPT_CBC));
1168 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1169 cipher.context_len =
1170 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1171 SILC_CIPHER_SIM_CONTEXT_LEN));
1172 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1174 /* Put the SIM to the table of all SIM's in server */
1175 server->sim = silc_realloc(server->sim,
1176 sizeof(*server->sim) *
1177 (server->sim_count + 1));
1178 server->sim[server->sim_count] = sim;
1179 server->sim_count++;
1181 SILC_LOG_ERROR(("Error configuring ciphers"));
1182 silc_server_stop(server);
1186 /* Register the cipher */
1187 silc_cipher_register(&cipher);
1195 /* Registers configured PKCS's. */
1196 /* XXX: This really doesn't do anything now since we have statically
1197 registered our PKCS's. This should be implemented when PKCS works
1198 as SIM's. This checks now only that the PKCS user requested is
1199 really out there. */
1201 void silc_config_server_register_pkcs(SilcConfigServer config)
1203 SilcConfigServerSectionAlg *alg = config->pkcs;
1204 SilcServer server = (SilcServer)config->server;
1205 SilcPKCS tmp = NULL;
1207 SILC_LOG_DEBUG(("Registering configured PKCS"));
1211 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1212 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1213 silc_server_stop(server);
1222 /* Registers configured hash functions. These can then be allocated by the
1223 server when needed. */
1225 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1227 SilcConfigServerSectionAlg *alg;
1228 SilcServer server = (SilcServer)config->server;
1230 SILC_LOG_DEBUG(("Registering configured hash functions"));
1232 alg = config->hash_func;
1235 if (!alg->sim_name) {
1236 /* Hash module is supposed to be built in. Nothing to be done
1237 here except to test that the hash function really is built in. */
1238 SilcHash tmp = NULL;
1240 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1241 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1242 silc_server_stop(server);
1249 /* Load (try at least) the hash SIM module */
1250 SilcHashObject hash;
1251 SilcSimContext *sim;
1253 memset(&hash, 0, sizeof(hash));
1254 hash.name = alg->alg_name;
1255 hash.block_len = alg->block_len;
1256 hash.hash_len = alg->key_len;
1258 sim = silc_sim_alloc();
1259 sim->type = SILC_SIM_HASH;
1260 sim->libname = alg->sim_name;
1262 if ((silc_sim_load(sim))) {
1264 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1265 SILC_HASH_SIM_INIT));
1266 SILC_LOG_DEBUG(("init=%p", hash.init));
1268 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1269 SILC_HASH_SIM_UPDATE));
1270 SILC_LOG_DEBUG(("update=%p", hash.update));
1272 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1273 SILC_HASH_SIM_FINAL));
1274 SILC_LOG_DEBUG(("final=%p", hash.final));
1276 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1277 SILC_HASH_SIM_CONTEXT_LEN));
1278 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1280 /* Put the SIM to the table of all SIM's in server */
1281 server->sim = silc_realloc(server->sim,
1282 sizeof(*server->sim) *
1283 (server->sim_count + 1));
1284 server->sim[server->sim_count] = sim;
1285 server->sim_count++;
1287 SILC_LOG_ERROR(("Error configuring hash functions"));
1288 silc_server_stop(server);
1292 /* Register the cipher */
1293 silc_hash_register(&hash);
1301 /* Returns client authentication information from server configuration
1302 by host (name or ip). */
1304 SilcConfigServerSectionClientConnection *
1305 silc_config_server_find_client_conn(SilcConfigServer config,
1306 char *host, int port)
1309 SilcConfigServerSectionClientConnection *client = NULL;
1314 if (!config->clients)
1317 client = config->clients;
1319 for (i = 0; client; i++) {
1320 if (silc_string_compare(client->host, host))
1322 client = client->next;
1331 /* Returns server connection info from server configuartion by host
1334 SilcConfigServerSectionServerConnection *
1335 silc_config_server_find_server_conn(SilcConfigServer config,
1336 char *host, int port)
1339 SilcConfigServerSectionServerConnection *serv = NULL;
1344 if (!config->servers)
1347 serv = config->servers;
1348 for (i = 0; serv; i++) {
1349 if (silc_string_compare(serv->host, host))
1360 /* Returns router connection info from server configuartion by
1361 host (name or ip). */
1363 SilcConfigServerSectionServerConnection *
1364 silc_config_server_find_router_conn(SilcConfigServer config,
1365 char *host, int port)
1368 SilcConfigServerSectionServerConnection *serv = NULL;
1373 if (!config->routers)
1376 serv = config->routers;
1377 for (i = 0; serv; i++) {
1378 if (silc_string_compare(serv->host, host))
1389 /* Prints out example configuration file with default built in
1390 configuration values. */
1392 void silc_config_server_print()
1398 # Automatically generated example SILCd configuration file with default\n\
1399 # built in values. Use this as a guide to configure your SILCd configuration\n\
1400 # file for your system. For detailed description of different configuration\n\
1401 # sections refer to silcd(8) manual page.\n\
1416 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1419 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1422 +10.2.1.6:10.2.1.6:1333
1425 +infologfile:silcd.log:10000
1426 #+warninglogfile:/var/log/silcd_warning.log:10000
1427 #+errorlogfile:ERROR.log:10000
1428 #+fatallogfile:/var/log/silcd_error.log:
1435 +10.2.1.199:priikone:333:1
1438 +10.2.1.199:priikone:priikone:1
1448 fprintf(stdout, "%s\n", buf);