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/???>:
130 <Port>:<Version ID>:<Class>:<Initiator>
134 This section is used to deny specific connections to your server. This
135 can be used to deny both clients and servers.
139 +<Remote address or name or nickname>:<Time interval>:<Comment>:<Port>
143 This section is used to set the alternate servers that clients will be
144 redirected to when our server is full.
148 +<Remote address or name>:<Port>
151 SilcConfigServerSection silc_config_server_sections[] = {
153 SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, 4 },
155 SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, 2 },
157 SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, 4 },
159 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, 4 },
161 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, 4 },
163 SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, 3 },
165 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
166 { "[ConnectionClass]",
167 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
168 { "[ClientConnection]",
169 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
170 { "[ServerConnection]",
171 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
172 { "[RouterConnection]",
173 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 7 },
174 { "[AdminConnection]",
175 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
176 { "[DenyConnection]",
177 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
178 { "[RedirectClient]",
179 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
181 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
183 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
186 /* Allocates a new configuration object, opens configuration file and
187 parses the file. The parsed data is returned to the newly allocated
188 configuration object. */
190 SilcConfigServer silc_config_server_alloc(char *filename)
192 SilcConfigServer new;
194 SilcConfigServerParse config_parse;
196 SILC_LOG_DEBUG(("Allocating new configuration object"));
198 new = silc_calloc(1, sizeof(*new));
200 fprintf(stderr, "Could not allocate new configuration object");
204 new->filename = filename;
206 /* Open configuration file and parse it */
209 silc_config_open(filename, &buffer);
212 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
214 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
226 /* Free's a configuration object. */
228 void silc_config_server_free(SilcConfigServer config)
231 silc_free(config->filename);
232 silc_free(config->server_info);
233 silc_free(config->admin_info);
234 silc_free(config->listen_port);
235 silc_free(config->conn_class);
236 silc_free(config->clients);
237 silc_free(config->admins);
238 silc_free(config->servers);
239 silc_free(config->routers);
240 silc_free(config->denied);
241 silc_free(config->redirect);
242 silc_free(config->motd);
247 /* Parses the the buffer and returns the parsed lines into return_config
248 argument. The return_config argument doesn't have to be initialized
249 before calling this. It will be initialized during the parsing. The
250 buffer sent as argument can be safely free'd after this function has
251 succesfully returned. */
253 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
254 SilcConfigServerParse *return_config)
257 unsigned int linenum;
258 char line[1024], *cp;
259 SilcConfigServerSection *cptr = NULL;
260 SilcConfigServerParse parse = *return_config, first = NULL;
262 SILC_LOG_DEBUG(("Parsing configuration file"));
266 while((begin = silc_gets(line, sizeof(line),
267 buffer->data, buffer->len, begin)) != EOF) {
271 /* Check for bad line */
272 if (silc_check_line(cp))
275 /* Remove tabs and whitespaces from the line */
276 if (strchr(cp, '\t')) {
278 while(strchr(cp + i, '\t')) {
279 *strchr(cp + i, '\t') = ' ';
283 for (i = 0; i < strlen(cp); i++) {
299 /* Remove new line sign */
300 if (strchr(cp, '\n'))
301 *strchr(cp, '\n') = '\0';
303 /* Check for matching sections */
304 for (cptr = silc_config_server_sections; cptr->section; cptr++)
305 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
308 if (!cptr->section) {
309 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
310 config->filename, linenum, cp);
317 * Start of a configuration line
320 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
322 if (strchr(cp, '\n'))
323 *strchr(cp, '\n') = ':';
326 parse = silc_calloc(1, sizeof(*parse));
328 parse->section = NULL;
332 if (parse->next == NULL) {
333 parse->next = silc_calloc(1, sizeof(*parse->next));
334 parse->next->line = NULL;
335 parse->next->section = NULL;
336 parse->next->next = NULL;
337 parse->next->prev = parse;
345 /* Add the line to parsing structure for further parsing. */
347 parse->section = cptr;
348 parse->line = silc_buffer_alloc(strlen(cp) + 1);
349 parse->linenum = linenum;
350 silc_buffer_pull_tail(parse->line, strlen(cp));
351 silc_buffer_put(parse->line, cp, strlen(cp));
358 /* Set the return_config argument to its first value so that further
359 parsing can be started from the first line. */
360 *return_config = first;
365 /* Parses the lines earlier read from configuration file. The config object
366 must not be initialized, it will be initialized in this function. The
367 parse_config argument is uninitialized automatically during this
370 int silc_config_server_parse_lines(SilcConfigServer config,
371 SilcConfigServerParse parse_config)
373 int ret, check = FALSE;
374 unsigned int checkmask;
376 SilcConfigServerParse pc = parse_config;
379 SILC_LOG_DEBUG(("Parsing configuration lines"));
389 /* Get number of tokens in line */
390 ret = silc_config_check_num_token(line);
391 if (ret != pc->section->maxfields) {
393 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
394 config->filename, pc->linenum, ret,
395 pc->section->maxfields);
400 switch(pc->section->type) {
401 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
403 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
405 /* Get cipher name */
406 ret = silc_config_get_token(line, &config->cipher->alg_name);
410 fprintf(stderr, "%s:%d: Cipher name not defined\n",
411 config->filename, pc->linenum);
415 /* Get module name */
416 config->cipher->sim_name = NULL;
417 ret = silc_config_get_token(line, &config->cipher->sim_name);
421 /* Get block length */
422 ret = silc_config_get_token(line, &tmp);
426 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
427 config->filename, pc->linenum);
430 config->cipher->block_len = atoi(tmp);
434 ret = silc_config_get_token(line, &tmp);
438 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
439 config->filename, pc->linenum);
442 config->cipher->key_len = atoi(tmp);
446 checkmask |= (1L << pc->section->type);
449 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
451 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
454 ret = silc_config_get_token(line, &config->pkcs->alg_name);
458 fprintf(stderr, "%s:%d: PKCS name not defined\n",
459 config->filename, pc->linenum);
464 ret = silc_config_get_token(line, &tmp);
468 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
469 config->filename, pc->linenum);
472 config->pkcs->key_len = atoi(tmp);
476 checkmask |= (1L << pc->section->type);
479 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
481 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
483 /* Get Hash function name */
484 ret = silc_config_get_token(line, &config->hash_func->alg_name);
488 fprintf(stderr, "%s:%d: Hash function name not defined\n",
489 config->filename, pc->linenum);
493 /* Get Hash function module name */
494 config->hash_func->sim_name = NULL;
495 ret = silc_config_get_token(line, &config->hash_func->sim_name);
499 /* Get block length */
500 ret = silc_config_get_token(line, &tmp);
504 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
505 config->filename, pc->linenum);
508 config->hash_func->block_len = atoi(tmp);
511 /* Get hash length */
512 ret = silc_config_get_token(line, &tmp);
516 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
517 config->filename, pc->linenum);
520 config->hash_func->key_len = atoi(tmp);
524 checkmask |= (1L << pc->section->type);
527 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
529 if (!config->server_info)
530 config->server_info = silc_calloc(1, sizeof(*config->server_info));
532 /* Get server name */
533 ret = silc_config_get_token(line, &config->server_info->server_name);
537 /* Server name not defined */
542 ret = silc_config_get_token(line, &config->server_info->server_ip);
546 /* Server IP not defined */
550 /* Get server location */
551 ret = silc_config_get_token(line, &config->server_info->location);
555 /* Get server port */
556 /* XXX: Need port here??? */
557 ret = silc_config_get_token(line, &tmp);
561 /* Port not defined */
564 config->server_info->port = atoi(tmp);
568 checkmask |= (1L << pc->section->type);
571 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
573 if (!config->admin_info)
574 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
577 ret = silc_config_get_token(line, &config->admin_info->location);
581 /* Get server type */
582 ret = silc_config_get_token(line, &config->admin_info->server_type);
586 /* Get admins name */
587 ret = silc_config_get_token(line, &config->admin_info->admin_name);
591 /* Get admins email address */
592 ret = silc_config_get_token(line, &config->admin_info->admin_email);
597 checkmask |= (1L << pc->section->type);
600 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
602 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
605 ret = silc_config_get_token(line, &config->listen_port->host);
610 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
615 ret = silc_config_get_token(line, &tmp);
620 config->listen_port->port = 0;
622 config->listen_port->port = atoi(tmp);
627 checkmask |= (1L << pc->section->type);
630 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
632 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
634 /* Get class number */
635 ret = silc_config_get_token(line, &tmp);
639 /* Class number not defined */
642 config->conn_class->class = atoi(tmp);
645 /* Get ping frequency */
646 ret = silc_config_get_token(line, &tmp);
649 config->conn_class->ping_freq = atoi(tmp);
652 /* Get connect frequency */
653 ret = silc_config_get_token(line, &tmp);
656 config->conn_class->connect_freq = atoi(tmp);
660 ret = silc_config_get_token(line, &tmp);
663 config->conn_class->max_links = atoi(tmp);
667 checkmask |= (1L << pc->section->type);
670 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
672 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
674 /* Get log section type and check it */
675 ret = silc_config_get_token(line, &config->logging->logtype);
679 fprintf(stderr, "%s:%d: Log file section not defined\n",
680 config->filename, pc->linenum);
683 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
684 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
685 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
686 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
687 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
688 config->filename, pc->linenum, config->logging->logtype);
692 /* Get log filename */
693 ret = silc_config_get_token(line, &config->logging->filename);
697 fprintf(stderr, "%s:%d: Log file name not defined\n",
698 config->filename, pc->linenum);
702 /* Get max byte size */
703 ret = silc_config_get_token(line, &tmp);
707 config->logging->maxsize = atoi(tmp);
712 checkmask |= (1L << pc->section->type);
715 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
717 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
720 ret = silc_config_get_token(line, &config->clients->host);
725 config->clients->host = strdup("*");
727 /* Get authentication method */
728 ret = silc_config_get_token(line, &tmp);
732 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
733 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
734 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
735 config->filename, pc->linenum, tmp);
739 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
740 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
742 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
743 config->clients->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
748 /* Get authentication data */
749 ret = silc_config_get_token(line, &config->clients->auth_data);
754 config->clients->host = strdup("*");
757 ret = silc_config_get_token(line, &tmp);
761 config->clients->port = atoi(tmp);
765 /* Get class number */
766 ret = silc_config_get_token(line, &tmp);
770 config->clients->class = atoi(tmp);
775 checkmask |= (1L << pc->section->type);
778 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
780 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
783 ret = silc_config_get_token(line, &config->servers->host);
788 config->servers->host = strdup("*");
790 /* Get authentication method */
791 ret = silc_config_get_token(line, &tmp);
795 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
796 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
797 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
798 config->filename, pc->linenum, tmp);
802 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
803 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
805 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
806 config->servers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
811 /* Get authentication data */
812 ret = silc_config_get_token(line, &config->servers->auth_data);
817 ret = silc_config_get_token(line, &tmp);
821 config->servers->port = atoi(tmp);
826 ret = silc_config_get_token(line, &config->servers->version);
830 /* Get class number */
831 ret = silc_config_get_token(line, &tmp);
835 config->servers->class = atoi(tmp);
840 checkmask |= (1L << pc->section->type);
843 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
845 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
848 ret = silc_config_get_token(line, &config->routers->host);
853 // config->routers->host = strdup("*");
855 /* Get authentication method */
856 ret = silc_config_get_token(line, &tmp);
860 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
861 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
862 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
863 config->filename, pc->linenum, tmp);
867 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
868 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
870 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
871 config->routers->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
876 /* Get authentication data */
877 ret = silc_config_get_token(line, &config->routers->auth_data);
882 ret = silc_config_get_token(line, &tmp);
886 config->routers->port = atoi(tmp);
891 ret = silc_config_get_token(line, &config->routers->version);
895 /* Get class number */
896 ret = silc_config_get_token(line, &tmp);
900 config->routers->class = atoi(tmp);
904 /* Get whether we are initiator or not */
905 ret = silc_config_get_token(line, &tmp);
909 config->routers->initiator = atoi(tmp);
910 if (config->routers->initiator != 0)
911 config->routers->initiator = TRUE;
916 checkmask |= (1L << pc->section->type);
919 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
921 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
924 ret = silc_config_get_token(line, &config->admins->host);
929 config->admins->host = strdup("*");
931 /* Get authentication method */
932 ret = silc_config_get_token(line, &tmp);
936 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
937 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
938 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
939 config->filename, pc->linenum, tmp);
943 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
944 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PASSWORD;
946 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
947 config->admins->auth_meth = SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY;
952 /* Get authentication data */
953 ret = silc_config_get_token(line, &config->admins->auth_data);
958 ret = silc_config_get_token(line, &config->admins->nickname);
962 /* Get class number */
963 ret = silc_config_get_token(line, &tmp);
967 config->admins->class = atoi(tmp);
972 checkmask |= (1L << pc->section->type);
975 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
976 /* Not implemented yet */
980 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
981 /* Not implemented yet */
985 case SILC_CONFIG_SERVER_SECTION_TYPE_MOTD:
988 config->motd = silc_calloc(1, sizeof(*config->motd));
991 ret = silc_config_get_token(line, &config->motd->motd_file);
996 checkmask |= (1L << pc->section->type);
999 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
1005 /* Check for error */
1006 if (check == FALSE) {
1007 /* Line could not be parsed */
1008 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
1014 // silc_free(pc->prev);
1021 /* Check that all mandatory sections really were found. If not, the server
1022 cannot function and we return error. */
1023 ret = silc_config_server_check_sections(checkmask);
1029 /* Before returning all the lists in the config object must be set
1030 to their first values (the last value is first here). */
1031 while (config->cipher && config->cipher->prev)
1032 config->cipher = config->cipher->prev;
1033 while (config->pkcs && config->pkcs->prev)
1034 config->pkcs = config->pkcs->prev;
1035 while (config->hash_func && config->hash_func->prev)
1036 config->hash_func = config->hash_func->prev;
1037 while (config->listen_port && config->listen_port->prev)
1038 config->listen_port = config->listen_port->prev;
1039 while (config->logging && config->logging->prev)
1040 config->logging = config->logging->prev;
1041 while (config->conn_class && config->conn_class->prev)
1042 config->conn_class = config->conn_class->prev;
1043 while (config->clients && config->clients->prev)
1044 config->clients = config->clients->prev;
1045 while (config->servers && config->servers->prev)
1046 config->servers = config->servers->prev;
1047 while (config->routers && config->routers->prev)
1048 config->routers = config->routers->prev;
1050 SILC_LOG_DEBUG(("Done"));
1055 /* This function checks that the mask sent as argument includes all the
1056 sections that are mandatory in SILC server. */
1058 int silc_config_server_check_sections(unsigned int checkmask)
1060 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1064 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1068 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1072 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1077 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1082 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1090 /* Sets log files where log messages is saved by the server. */
1092 void silc_config_server_setlogfiles(SilcConfigServer config)
1094 SilcConfigServerSectionLogging *log;
1095 char *info, *warning, *error, *fatal;
1096 unsigned int info_size, warning_size, error_size, fatal_size;
1098 SILC_LOG_DEBUG(("Setting configured log file names"));
1100 /* Set default files before checking configuration */
1101 info = SILC_LOG_FILE_INFO;
1102 warning = SILC_LOG_FILE_WARNING;
1103 error = SILC_LOG_FILE_ERROR;
1104 fatal = SILC_LOG_FILE_FATAL;
1110 log = config->logging;
1112 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1113 info = log->filename;
1114 info_size = log->maxsize;
1116 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1117 warning = log->filename;
1118 warning_size = log->maxsize;
1120 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1121 error = log->filename;
1122 error_size = log->maxsize;
1124 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1125 fatal = log->filename;
1126 fatal_size = log->maxsize;
1132 silc_log_set_files(info, info_size, warning, warning_size,
1133 error, error_size, fatal, fatal_size);
1136 /* Registers configured ciphers. These can then be allocated by the
1137 server when needed. */
1139 void silc_config_server_register_ciphers(SilcConfigServer config)
1141 SilcConfigServerSectionAlg *alg;
1142 SilcServer server = (SilcServer)config->server;
1144 SILC_LOG_DEBUG(("Registering configured ciphers"));
1146 alg = config->cipher;
1149 if (!alg->sim_name) {
1150 /* Crypto module is supposed to be built in. Nothing to be done
1151 here except to test that the cipher really is built in. */
1152 SilcCipher tmp = NULL;
1154 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1155 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1156 silc_server_stop(server);
1159 silc_cipher_free(tmp);
1163 /* Load (try at least) the crypto SIM module */
1164 SilcCipherObject cipher;
1165 SilcSimContext *sim;
1167 memset(&cipher, 0, sizeof(cipher));
1168 cipher.name = alg->alg_name;
1169 cipher.block_len = alg->block_len;
1170 cipher.key_len = alg->key_len * 8;
1172 sim = silc_sim_alloc();
1173 sim->type = SILC_SIM_CIPHER;
1174 sim->libname = alg->sim_name;
1176 if ((silc_sim_load(sim))) {
1178 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1179 SILC_CIPHER_SIM_SET_KEY));
1180 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1181 cipher.set_key_with_string =
1182 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1183 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1184 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1186 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1187 SILC_CIPHER_SIM_ENCRYPT_CBC));
1188 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1190 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1191 SILC_CIPHER_SIM_DECRYPT_CBC));
1192 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1193 cipher.context_len =
1194 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1195 SILC_CIPHER_SIM_CONTEXT_LEN));
1196 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1198 /* Put the SIM to the list of all SIM's in server */
1199 silc_dlist_add(server->sim, sim);
1201 SILC_LOG_ERROR(("Error configuring ciphers"));
1202 silc_server_stop(server);
1206 /* Register the cipher */
1207 silc_cipher_register(&cipher);
1215 /* Registers configured PKCS's. */
1216 /* XXX: This really doesn't do anything now since we have statically
1217 registered our PKCS's. This should be implemented when PKCS works
1218 as SIM's. This checks now only that the PKCS user requested is
1219 really out there. */
1221 void silc_config_server_register_pkcs(SilcConfigServer config)
1223 SilcConfigServerSectionAlg *alg = config->pkcs;
1224 SilcServer server = (SilcServer)config->server;
1225 SilcPKCS tmp = NULL;
1227 SILC_LOG_DEBUG(("Registering configured PKCS"));
1231 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1232 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1233 silc_server_stop(server);
1242 /* Registers configured hash functions. These can then be allocated by the
1243 server when needed. */
1245 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1247 SilcConfigServerSectionAlg *alg;
1248 SilcServer server = (SilcServer)config->server;
1250 SILC_LOG_DEBUG(("Registering configured hash functions"));
1252 alg = config->hash_func;
1255 if (!alg->sim_name) {
1256 /* Hash module is supposed to be built in. Nothing to be done
1257 here except to test that the hash function really is built in. */
1258 SilcHash tmp = NULL;
1260 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1261 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1262 silc_server_stop(server);
1269 /* Load (try at least) the hash SIM module */
1270 SilcHashObject hash;
1271 SilcSimContext *sim;
1273 memset(&hash, 0, sizeof(hash));
1274 hash.name = alg->alg_name;
1275 hash.block_len = alg->block_len;
1276 hash.hash_len = alg->key_len;
1278 sim = silc_sim_alloc();
1279 sim->type = SILC_SIM_HASH;
1280 sim->libname = alg->sim_name;
1282 if ((silc_sim_load(sim))) {
1284 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1285 SILC_HASH_SIM_INIT));
1286 SILC_LOG_DEBUG(("init=%p", hash.init));
1288 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1289 SILC_HASH_SIM_UPDATE));
1290 SILC_LOG_DEBUG(("update=%p", hash.update));
1292 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1293 SILC_HASH_SIM_FINAL));
1294 SILC_LOG_DEBUG(("final=%p", hash.final));
1296 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1297 SILC_HASH_SIM_CONTEXT_LEN));
1298 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1300 /* Put the SIM to the table of all SIM's in server */
1301 silc_dlist_add(server->sim, sim);
1303 SILC_LOG_ERROR(("Error configuring hash functions"));
1304 silc_server_stop(server);
1308 /* Register the cipher */
1309 silc_hash_register(&hash);
1317 /* Returns client authentication information from server configuration
1318 by host (name or ip). */
1320 SilcConfigServerSectionClientConnection *
1321 silc_config_server_find_client_conn(SilcConfigServer config,
1322 char *host, int port)
1325 SilcConfigServerSectionClientConnection *client = NULL;
1330 if (!config->clients)
1333 client = config->clients;
1335 for (i = 0; client; i++) {
1336 if (silc_string_compare(client->host, host))
1338 client = client->next;
1347 /* Returns server connection info from server configuartion by host
1350 SilcConfigServerSectionServerConnection *
1351 silc_config_server_find_server_conn(SilcConfigServer config,
1352 char *host, int port)
1355 SilcConfigServerSectionServerConnection *serv = NULL;
1360 if (!config->servers)
1363 serv = config->servers;
1364 for (i = 0; serv; i++) {
1365 if (silc_string_compare(serv->host, host))
1376 /* Returns router connection info from server configuartion by
1377 host (name or ip). */
1379 SilcConfigServerSectionServerConnection *
1380 silc_config_server_find_router_conn(SilcConfigServer config,
1381 char *host, int port)
1384 SilcConfigServerSectionServerConnection *serv = NULL;
1389 if (!config->routers)
1392 serv = config->routers;
1393 for (i = 0; serv; i++) {
1394 if (silc_string_compare(serv->host, host))
1405 /* Prints out example configuration file with default built in
1406 configuration values. */
1408 void silc_config_server_print()
1414 # Automatically generated example SILCd configuration file with default\n\
1415 # built in values. Use this as a guide to configure your SILCd configuration\n\
1416 # file for your system. For detailed description of different configuration\n\
1417 # sections refer to silcd(8) manual page.\n\
1432 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1435 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1438 +10.2.1.6:10.2.1.6:1333
1441 +infologfile:silcd.log:10000
1442 #+warninglogfile:/var/log/silcd_warning.log:10000
1443 #+errorlogfile:ERROR.log:10000
1444 #+fatallogfile:/var/log/silcd_error.log:
1451 +10.2.1.199:priikone:333:1
1454 +10.2.1.199:priikone:priikone:1
1464 fprintf(stdout, "%s\n", buf);