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.3 2000/07/10 05:41:20 priikone
24 * Added missing token to administrative information.
26 * Revision 1.2 2000/07/05 06:14:01 priikone
27 * Global costemic changes.
29 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
30 * Imported from internal CVS/Added Log headers.
35 #include "serverincludes.h"
36 #include "server_internal.h"
39 All possible configuration sections for SILC server.
45 +<Cipher name>:<SIM path>
51 +<PKCS name>:<key length>
57 +<Hash function name>:<SIM path>
61 This section is used to set the server informations.
65 +<Server DNS name>:<Server IP>:<Geographic location>:<Port>
69 This section is used to set the server's administrative information.
73 +<Location>:<Server type>:<Admin's name>:<Admin's email address>
77 This section is used to set ports the server is listenning.
81 +<Local IP/UNIX socket path>:<Remote IP>:<Port>
85 This section is used to set various logging files, their paths
86 and maximum sizes. All the other directives except those defined
87 below are ignored in this section. Log files are purged after they
88 reach the maximum set byte size.
92 +infologfile:<path>:<max byte size>
93 +errorlogfile:<path>:<max byte size>
97 This section is used to define connection classes. These can be
98 used to optimize the server and the connections.
102 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
106 This section is used to define client authentications.
110 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
114 This section is used to define the server's administration
119 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
123 This section is used to define the server connections to this
124 server/router. Only routers can have normal server connections.
125 Normal servers leave this section epmty. The remote server cannot be
126 older than specified Version ID.
130 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
134 This section is used to define the router connections to this
135 server/router. Both normal server and router can have router
136 connections. Normal server usually has only one connection while
137 a router can have multiple. The remote server cannot be older than
138 specified Version ID.
142 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
146 This section is used to deny specific connections to your server. This
147 can be used to deny both clients and servers.
151 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
155 This section is used to set the alternate servers that clients will be
156 redirected to when our server is full.
160 +<Remote address or name>:<Port>
163 SilcConfigServerSection silc_config_server_sections[] = {
165 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
167 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
169 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
171 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
173 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
175 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
177 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
178 { "[ConnectionClass]",
179 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
180 { "[ClientConnection]",
181 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
182 { "[ServerConnection]",
183 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
184 { "[RouterConnection]",
185 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 6 },
186 { "[AdminConnection]",
187 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
188 { "[DenyConnection]",
189 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
190 { "[RedirectClient]",
191 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
193 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
196 /* Allocates a new configuration object, opens configuration file and
197 parses the file. The parsed data is returned to the newly allocated
198 configuration object. */
200 SilcConfigServer silc_config_server_alloc(char *filename)
202 SilcConfigServer new;
204 SilcConfigServerParse config_parse;
206 SILC_LOG_DEBUG(("Allocating new configuration object"));
208 new = silc_calloc(1, sizeof(*new));
210 fprintf(stderr, "Could not allocate new configuration object");
214 new->filename = filename;
216 /* Open configuration file and parse it */
219 silc_config_open(filename, &buffer);
222 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
224 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
236 /* Free's a configuration object. */
238 void silc_config_server_free(SilcConfigServer config)
241 silc_free(config->filename);
242 silc_free(config->server_info);
243 silc_free(config->admin_info);
244 silc_free(config->listen_port);
245 silc_free(config->conn_class);
246 silc_free(config->clients);
247 silc_free(config->admins);
248 silc_free(config->servers);
249 silc_free(config->routers);
250 silc_free(config->denied);
251 silc_free(config->redirect);
256 /* Parses the the buffer and returns the parsed lines into return_config
257 argument. The return_config argument doesn't have to be initialized
258 before calling this. It will be initialized during the parsing. The
259 buffer sent as argument can be safely free'd after this function has
260 succesfully returned. */
262 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
263 SilcConfigServerParse *return_config)
266 unsigned int linenum;
267 char line[1024], *cp;
268 SilcConfigServerSection *cptr = NULL;
269 SilcConfigServerParse parse = *return_config, first = NULL;
271 SILC_LOG_DEBUG(("Parsing configuration file"));
275 while((begin = silc_gets(line, sizeof(line),
276 buffer->data, buffer->len, begin)) != EOF) {
280 /* Check for bad line */
281 if (silc_check_line(cp))
284 /* Remove tabs and whitespaces from the line */
285 if (strchr(cp, '\t')) {
287 while(strchr(cp + i, '\t')) {
288 *strchr(cp + i, '\t') = ' ';
292 for (i = 0; i < strlen(cp); i++) {
308 /* Remove new line sign */
309 if (strchr(cp, '\n'))
310 *strchr(cp, '\n') = '\0';
312 /* Check for matching sections */
313 for (cptr = silc_config_server_sections; cptr->section; cptr++)
314 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
317 if (!cptr->section) {
318 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
319 config->filename, linenum, cp);
326 * Start of a configuration line
329 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
331 if (strchr(cp, '\n'))
332 *strchr(cp, '\n') = ':';
335 parse = silc_calloc(1, sizeof(*parse));
337 parse->section = NULL;
341 if (parse->next == NULL) {
342 parse->next = silc_calloc(1, sizeof(*parse->next));
343 parse->next->line = NULL;
344 parse->next->section = NULL;
345 parse->next->next = NULL;
346 parse->next->prev = parse;
354 /* Add the line to parsing structure for further parsing. */
356 parse->section = cptr;
357 parse->line = silc_buffer_alloc(strlen(cp) + 1);
358 parse->linenum = linenum;
359 silc_buffer_pull_tail(parse->line, strlen(cp));
360 silc_buffer_put(parse->line, cp, strlen(cp));
367 /* Set the return_config argument to its first value so that further
368 parsing can be started from the first line. */
369 *return_config = first;
374 /* Parses the lines earlier read from configuration file. The config object
375 must not be initialized, it will be initialized in this function. The
376 parse_config argument is uninitialized automatically during this
379 int silc_config_server_parse_lines(SilcConfigServer config,
380 SilcConfigServerParse parse_config)
382 int ret, check = FALSE;
383 unsigned int checkmask;
385 SilcConfigServerParse pc = parse_config;
388 SILC_LOG_DEBUG(("Parsing configuration lines"));
398 /* Get number of tokens in line */
399 ret = silc_config_check_num_token(line);
400 if (ret != pc->section->maxfields) {
402 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
403 config->filename, pc->linenum, ret,
404 pc->section->maxfields);
409 switch(pc->section->type) {
410 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
412 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
414 /* Get cipher name */
415 ret = silc_config_get_token(line, &config->cipher->alg_name);
419 fprintf(stderr, "%s:%d: Cipher name not defined\n",
420 config->filename, pc->linenum);
424 /* Get module name */
425 config->cipher->sim_name = NULL;
426 ret = silc_config_get_token(line, &config->cipher->sim_name);
430 /* Get block length */
431 ret = silc_config_get_token(line, &tmp);
435 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
436 config->filename, pc->linenum);
439 config->cipher->block_len = atoi(tmp);
443 ret = silc_config_get_token(line, &tmp);
447 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
448 config->filename, pc->linenum);
451 config->cipher->key_len = atoi(tmp);
455 checkmask |= (1L << pc->section->type);
458 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
460 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
463 ret = silc_config_get_token(line, &config->pkcs->alg_name);
467 fprintf(stderr, "%s:%d: PKCS name not defined\n",
468 config->filename, pc->linenum);
473 ret = silc_config_get_token(line, &tmp);
477 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
478 config->filename, pc->linenum);
481 config->pkcs->key_len = atoi(tmp);
485 checkmask |= (1L << pc->section->type);
488 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
490 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
492 /* Get Hash function name */
493 ret = silc_config_get_token(line, &config->hash_func->alg_name);
497 fprintf(stderr, "%s:%d: Hash function name not defined\n",
498 config->filename, pc->linenum);
502 /* Get Hash function module name */
503 config->hash_func->sim_name = NULL;
504 ret = silc_config_get_token(line, &config->hash_func->sim_name);
508 /* Get block length */
509 ret = silc_config_get_token(line, &tmp);
513 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
514 config->filename, pc->linenum);
517 config->hash_func->block_len = atoi(tmp);
520 /* Get hash length */
521 ret = silc_config_get_token(line, &tmp);
525 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
526 config->filename, pc->linenum);
529 config->hash_func->key_len = atoi(tmp);
533 checkmask |= (1L << pc->section->type);
536 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
538 if (!config->server_info)
539 config->server_info = silc_calloc(1, sizeof(*config->server_info));
541 /* Get server name */
542 ret = silc_config_get_token(line, &config->server_info->server_name);
546 /* Server name not defined */
551 ret = silc_config_get_token(line, &config->server_info->server_ip);
555 /* Server IP not defined */
559 /* Get server location */
560 ret = silc_config_get_token(line, &config->server_info->location);
564 /* Get server port */
565 /* XXX: Need port here??? */
566 ret = silc_config_get_token(line, &tmp);
570 /* Port not defined */
573 config->server_info->port = atoi(tmp);
577 checkmask |= (1L << pc->section->type);
580 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
582 if (!config->admin_info)
583 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
586 ret = silc_config_get_token(line, &config->admin_info->location);
590 /* Get server type */
591 ret = silc_config_get_token(line, &config->admin_info->server_type);
595 /* Get admins name */
596 ret = silc_config_get_token(line, &config->admin_info->admin_name);
600 /* Get admins email address */
601 ret = silc_config_get_token(line, &config->admin_info->admin_email);
606 checkmask |= (1L << pc->section->type);
609 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
611 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
614 ret = silc_config_get_token(line, &config->listen_port->host);
619 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
624 ret = silc_config_get_token(line, &tmp);
629 config->listen_port->port = 0;
631 config->listen_port->port = atoi(tmp);
636 checkmask |= (1L << pc->section->type);
639 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
641 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
643 /* Get class number */
644 ret = silc_config_get_token(line, &tmp);
648 /* Class number not defined */
651 config->conn_class->class = atoi(tmp);
654 /* Get ping frequency */
655 ret = silc_config_get_token(line, &tmp);
658 config->conn_class->ping_freq = atoi(tmp);
661 /* Get connect frequency */
662 ret = silc_config_get_token(line, &tmp);
665 config->conn_class->connect_freq = atoi(tmp);
669 ret = silc_config_get_token(line, &tmp);
672 config->conn_class->max_links = atoi(tmp);
676 checkmask |= (1L << pc->section->type);
679 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
681 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
683 /* Get log section type and check it */
684 ret = silc_config_get_token(line, &config->logging->logtype);
688 fprintf(stderr, "%s:%d: Log file section not defined\n",
689 config->filename, pc->linenum);
692 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
693 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
694 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
695 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
696 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
697 config->filename, pc->linenum, config->logging->logtype);
701 /* Get log filename */
702 ret = silc_config_get_token(line, &config->logging->filename);
706 fprintf(stderr, "%s:%d: Log file name not defined\n",
707 config->filename, pc->linenum);
711 /* Get max byte size */
712 ret = silc_config_get_token(line, &tmp);
716 config->logging->maxsize = atoi(tmp);
721 checkmask |= (1L << pc->section->type);
724 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
726 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
729 ret = silc_config_get_token(line, &config->clients->host);
734 config->clients->host = strdup("*");
736 /* Get authentication method */
737 ret = silc_config_get_token(line, &tmp);
741 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
742 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
743 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
744 config->filename, pc->linenum, tmp);
748 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
749 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
751 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
752 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
757 /* Get authentication data */
758 ret = silc_config_get_token(line, &config->clients->auth_data);
763 config->clients->host = strdup("*");
766 ret = silc_config_get_token(line, &tmp);
770 config->clients->port = atoi(tmp);
774 /* Get class number */
775 ret = silc_config_get_token(line, &tmp);
779 config->clients->class = atoi(tmp);
784 checkmask |= (1L << pc->section->type);
787 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
789 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
792 ret = silc_config_get_token(line, &config->servers->host);
797 config->servers->host = strdup("*");
799 /* Get authentication method */
800 ret = silc_config_get_token(line, &tmp);
804 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
805 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
806 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
807 config->filename, pc->linenum, tmp);
811 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
812 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
814 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
815 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
820 /* Get authentication data */
821 ret = silc_config_get_token(line, &config->servers->auth_data);
826 ret = silc_config_get_token(line, &tmp);
830 config->servers->port = atoi(tmp);
835 ret = silc_config_get_token(line, &config->servers->version);
839 /* Get class number */
840 ret = silc_config_get_token(line, &tmp);
844 config->servers->class = atoi(tmp);
849 checkmask |= (1L << pc->section->type);
852 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
854 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
857 ret = silc_config_get_token(line, &config->routers->host);
862 // config->routers->host = strdup("*");
864 /* Get authentication method */
865 ret = silc_config_get_token(line, &tmp);
869 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
870 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
871 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
872 config->filename, pc->linenum, tmp);
876 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
877 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
879 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
880 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
885 /* Get authentication data */
886 ret = silc_config_get_token(line, &config->routers->auth_data);
891 ret = silc_config_get_token(line, &tmp);
895 config->routers->port = atoi(tmp);
900 ret = silc_config_get_token(line, &config->routers->version);
904 /* Get class number */
905 ret = silc_config_get_token(line, &tmp);
909 config->routers->class = atoi(tmp);
914 checkmask |= (1L << pc->section->type);
917 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
919 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
922 ret = silc_config_get_token(line, &config->admins->host);
927 config->admins->host = strdup("*");
929 /* Get authentication method */
930 ret = silc_config_get_token(line, &tmp);
934 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
935 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
936 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
937 config->filename, pc->linenum, tmp);
941 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
942 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
944 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
945 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
950 /* Get authentication data */
951 ret = silc_config_get_token(line, &config->admins->auth_data);
956 ret = silc_config_get_token(line, &config->admins->nickname);
960 /* Get class number */
961 ret = silc_config_get_token(line, &tmp);
965 config->admins->class = atoi(tmp);
970 checkmask |= (1L << pc->section->type);
973 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
974 /* Not implemented yet */
978 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
979 /* Not implemented yet */
983 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
989 /* Check for error */
990 if (check == FALSE) {
991 /* Line could not be parsed */
992 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
998 // silc_free(pc->prev);
1005 /* Check that all mandatory sections really were found. If not, the server
1006 cannot function and we return error. */
1007 ret = silc_config_server_check_sections(checkmask);
1013 /* Before returning all the lists in the config object must be set
1014 to their first values (the last value is first here). */
1015 while (config->cipher && config->cipher->prev)
1016 config->cipher = config->cipher->prev;
1017 while (config->pkcs && config->pkcs->prev)
1018 config->pkcs = config->pkcs->prev;
1019 while (config->hash_func && config->hash_func->prev)
1020 config->hash_func = config->hash_func->prev;
1021 while (config->listen_port && config->listen_port->prev)
1022 config->listen_port = config->listen_port->prev;
1023 while (config->logging && config->logging->prev)
1024 config->logging = config->logging->prev;
1025 while (config->conn_class && config->conn_class->prev)
1026 config->conn_class = config->conn_class->prev;
1027 while (config->clients && config->clients->prev)
1028 config->clients = config->clients->prev;
1029 while (config->servers && config->servers->prev)
1030 config->servers = config->servers->prev;
1031 while (config->routers && config->routers->prev)
1032 config->routers = config->routers->prev;
1034 SILC_LOG_DEBUG(("Done"));
1039 /* This function checks that the mask sent as argument includes all the
1040 sections that are mandatory in SILC server. */
1042 int silc_config_server_check_sections(unsigned int checkmask)
1044 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1048 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1052 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1056 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1061 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1066 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1074 /* Sets log files where log messages is saved by the server. */
1076 void silc_config_server_setlogfiles(SilcConfigServer config)
1078 SilcConfigServerSectionLogging *log;
1079 char *info, *warning, *error, *fatal;
1080 unsigned int info_size, warning_size, error_size, fatal_size;
1082 SILC_LOG_DEBUG(("Setting configured log file names"));
1084 /* Set default files before checking configuration */
1085 info = SILC_LOG_FILE_INFO;
1086 warning = SILC_LOG_FILE_WARNING;
1087 error = SILC_LOG_FILE_ERROR;
1088 fatal = SILC_LOG_FILE_FATAL;
1094 log = config->logging;
1096 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1097 info = log->filename;
1098 info_size = log->maxsize;
1100 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1101 warning = log->filename;
1102 warning_size = log->maxsize;
1104 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1105 error = log->filename;
1106 error_size = log->maxsize;
1108 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1109 fatal = log->filename;
1110 fatal_size = log->maxsize;
1116 silc_log_set_files(info, info_size, warning, warning_size,
1117 error, error_size, fatal, fatal_size);
1120 /* Registers configured ciphers. These can then be allocated by the
1121 server when needed. */
1123 void silc_config_server_register_ciphers(SilcConfigServer config)
1125 SilcConfigServerSectionAlg *alg;
1126 SilcServer server = (SilcServer)config->server;
1128 SILC_LOG_DEBUG(("Registering configured ciphers"));
1130 alg = config->cipher;
1133 if (!alg->sim_name) {
1134 /* Crypto module is supposed to be built in. Nothing to be done
1135 here except to test that the cipher really is built in. */
1136 SilcCipher tmp = NULL;
1138 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1139 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1140 silc_server_stop(server);
1143 silc_cipher_free(tmp);
1147 /* Load (try at least) the crypto SIM module */
1148 SilcCipherObject cipher;
1149 SilcSimContext *sim;
1151 memset(&cipher, 0, sizeof(cipher));
1152 cipher.name = alg->alg_name;
1153 cipher.block_len = alg->block_len;
1154 cipher.key_len = alg->key_len * 8;
1156 sim = silc_sim_alloc();
1157 sim->type = SILC_SIM_CIPHER;
1158 sim->libname = alg->sim_name;
1160 if ((silc_sim_load(sim))) {
1162 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1163 SILC_CIPHER_SIM_SET_KEY));
1164 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1165 cipher.set_key_with_string =
1166 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1167 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1168 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1170 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1171 SILC_CIPHER_SIM_ENCRYPT_CBC));
1172 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1174 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1175 SILC_CIPHER_SIM_DECRYPT_CBC));
1176 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1177 cipher.context_len =
1178 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1179 SILC_CIPHER_SIM_CONTEXT_LEN));
1180 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1182 /* Put the SIM to the table of all SIM's in server */
1183 server->sim = silc_realloc(server->sim,
1184 sizeof(*server->sim) *
1185 (server->sim_count + 1));
1186 server->sim[server->sim_count] = sim;
1187 server->sim_count++;
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 server->sim = silc_realloc(server->sim,
1290 sizeof(*server->sim) *
1291 (server->sim_count + 1));
1292 server->sim[server->sim_count] = sim;
1293 server->sim_count++;
1295 SILC_LOG_ERROR(("Error configuring hash functions"));
1296 silc_server_stop(server);
1300 /* Register the cipher */
1301 silc_hash_register(&hash);
1309 /* Returns client authentication information from server configuration
1310 by host (name or ip). */
1312 SilcConfigServerSectionClientConnection *
1313 silc_config_server_find_client_conn(SilcConfigServer config,
1314 char *host, int port)
1317 SilcConfigServerSectionClientConnection *client = NULL;
1322 if (!config->clients)
1325 client = config->clients;
1327 for (i = 0; client; i++) {
1328 if (silc_string_compare(client->host, host))
1330 client = client->next;
1339 /* Returns server connection info from server configuartion by host
1342 SilcConfigServerSectionServerConnection *
1343 silc_config_server_find_server_conn(SilcConfigServer config,
1344 char *host, int port)
1347 SilcConfigServerSectionServerConnection *serv = NULL;
1352 if (!config->servers)
1355 serv = config->servers;
1356 for (i = 0; serv; i++) {
1357 if (silc_string_compare(serv->host, host))
1368 /* Returns router connection info from server configuartion by
1369 host (name or ip). */
1371 SilcConfigServerSectionServerConnection *
1372 silc_config_server_find_router_conn(SilcConfigServer config,
1373 char *host, int port)
1376 SilcConfigServerSectionServerConnection *serv = NULL;
1381 if (!config->routers)
1384 serv = config->routers;
1385 for (i = 0; serv; i++) {
1386 if (silc_string_compare(serv->host, host))
1397 /* Prints out example configuration file with default built in
1398 configuration values. */
1400 void silc_config_server_print()
1406 # Automatically generated example SILCd configuration file with default\n\
1407 # built in values. Use this as a guide to configure your SILCd configuration\n\
1408 # file for your system. For detailed description of different configuration\n\
1409 # sections refer to silcd(8) manual page.\n\
1424 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1427 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1430 +10.2.1.6:10.2.1.6:1333
1433 +infologfile:silcd.log:10000
1434 #+warninglogfile:/var/log/silcd_warning.log:10000
1435 #+errorlogfile:ERROR.log:10000
1436 #+fatallogfile:/var/log/silcd_error.log:
1443 +10.2.1.199:priikone:333:1
1446 +10.2.1.199:priikone:priikone:1
1456 fprintf(stdout, "%s\n", buf);