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 both the user and group which silcd
73 sets itself upon starting.
81 This section is used to set various logging files, their paths
82 and maximum sizes. All the other directives except those defined
83 below are ignored in this section. Log files are purged after they
84 reach the maximum set byte size.
88 +infologfile:<path>:<max byte size>
89 +errorlogfile:<path>:<max byte size>
93 This section is used to define connection classes. These can be
94 used to optimize the server and the connections.
98 +<Class number>:<Ping freq>:<Connect freq>:<Max links>
102 This section is used to define client authentications.
106 +<Remote address or name>:<auth method>:<password/cert/key/???>:<Port>:<Class>
110 This section is used to define the server's administration
115 +<Hostname>:<auth method>:<password/cert/key/???>:<Nickname hash>:<Class>
119 This section is used to define the server connections to this
120 server/router. Only routers can have normal server connections.
121 Normal servers leave this section epmty. The remote server cannot be
122 older than specified Version ID.
126 +<Remote address or name>:<auth method>:<password/key/???>:<Port>:<Version ID>:<Class>
130 This section is used to define the router connections to this
131 server/router. Both normal server and router can have router
132 connections. Normal server usually has only one connection while
133 a router can have multiple. The remote server cannot be older than
134 specified Version ID.
138 +<Remote address or name>:<auth method>:<password/key/???>:
139 <Port>:<Version ID>:<Class>:<Initiator>
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_IDENTITY, 2 },
176 SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, 3 },
177 { "[ConnectionClass]",
178 SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, 4 },
179 { "[ClientConnection]",
180 SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, 5 },
181 { "[ServerConnection]",
182 SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, 6 },
183 { "[RouterConnection]",
184 SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, 7 },
185 { "[AdminConnection]",
186 SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
187 { "[DenyConnection]",
188 SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
189 { "[RedirectClient]",
190 SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
192 SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
194 { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
197 /* Allocates a new configuration object, opens configuration file and
198 parses the file. The parsed data is returned to the newly allocated
199 configuration object. */
201 SilcConfigServer silc_config_server_alloc(char *filename)
203 SilcConfigServer new;
205 SilcConfigServerParse config_parse;
207 SILC_LOG_DEBUG(("Allocating new configuration object"));
209 new = silc_calloc(1, sizeof(*new));
211 fprintf(stderr, "Could not allocate new configuration object");
215 new->filename = filename;
217 /* Open configuration file and parse it */
220 silc_config_open(filename, &buffer);
223 if ((silc_config_server_parse(new, buffer, &config_parse)) == FALSE)
225 if ((silc_config_server_parse_lines(new, config_parse)) == FALSE)
237 /* Free's a configuration object. */
239 void silc_config_server_free(SilcConfigServer config)
242 silc_free(config->filename);
243 silc_free(config->server_info);
244 silc_free(config->admin_info);
245 silc_free(config->listen_port);
246 silc_free(config->identity);
247 silc_free(config->conn_class);
248 silc_free(config->clients);
249 silc_free(config->admins);
250 silc_free(config->servers);
251 silc_free(config->routers);
252 silc_free(config->denied);
253 silc_free(config->redirect);
254 silc_free(config->motd);
259 /* Parses the the buffer and returns the parsed lines into return_config
260 argument. The return_config argument doesn't have to be initialized
261 before calling this. It will be initialized during the parsing. The
262 buffer sent as argument can be safely free'd after this function has
263 succesfully returned. */
265 int silc_config_server_parse(SilcConfigServer config, SilcBuffer buffer,
266 SilcConfigServerParse *return_config)
269 unsigned int linenum;
270 char line[1024], *cp;
271 SilcConfigServerSection *cptr = NULL;
272 SilcConfigServerParse parse = *return_config, first = NULL;
274 SILC_LOG_DEBUG(("Parsing configuration file"));
278 while((begin = silc_gets(line, sizeof(line),
279 buffer->data, buffer->len, begin)) != EOF) {
283 /* Check for bad line */
284 if (silc_check_line(cp))
287 /* Remove tabs and whitespaces from the line */
288 if (strchr(cp, '\t')) {
290 while(strchr(cp + i, '\t')) {
291 *strchr(cp + i, '\t') = ' ';
295 for (i = 0; i < strlen(cp); i++) {
311 /* Remove new line sign */
312 if (strchr(cp, '\n'))
313 *strchr(cp, '\n') = '\0';
315 /* Check for matching sections */
316 for (cptr = silc_config_server_sections; cptr->section; cptr++)
317 if (!strncasecmp(cp, cptr->section, strlen(cptr->section)))
320 if (!cptr->section) {
321 fprintf(stderr, "%s:%d: Unknown section `%s'\n",
322 config->filename, linenum, cp);
329 * Start of a configuration line
332 if (cptr->type != SILC_CONFIG_SERVER_SECTION_TYPE_NONE) {
334 if (strchr(cp, '\n'))
335 *strchr(cp, '\n') = ':';
338 parse = silc_calloc(1, sizeof(*parse));
340 parse->section = NULL;
344 if (parse->next == NULL) {
345 parse->next = silc_calloc(1, sizeof(*parse->next));
346 parse->next->line = NULL;
347 parse->next->section = NULL;
348 parse->next->next = NULL;
349 parse->next->prev = parse;
357 /* Add the line to parsing structure for further parsing. */
359 parse->section = cptr;
360 parse->line = silc_buffer_alloc(strlen(cp) + 1);
361 parse->linenum = linenum;
362 silc_buffer_pull_tail(parse->line, strlen(cp));
363 silc_buffer_put(parse->line, cp, strlen(cp));
370 /* Set the return_config argument to its first value so that further
371 parsing can be started from the first line. */
372 *return_config = first;
377 /* Parses the lines earlier read from configuration file. The config object
378 must not be initialized, it will be initialized in this function. The
379 parse_config argument is uninitialized automatically during this
382 int silc_config_server_parse_lines(SilcConfigServer config,
383 SilcConfigServerParse parse_config)
385 int ret, check = FALSE;
386 unsigned int checkmask;
388 SilcConfigServerParse pc = parse_config;
391 SILC_LOG_DEBUG(("Parsing configuration lines"));
401 /* Get number of tokens in line */
402 ret = silc_config_check_num_token(line);
403 if (ret != pc->section->maxfields) {
405 fprintf(stderr, "%s:%d: Missing tokens, %d tokens (should be %d)\n",
406 config->filename, pc->linenum, ret,
407 pc->section->maxfields);
412 switch(pc->section->type) {
413 case SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER:
415 SILC_SERVER_CONFIG_LIST_ALLOC(config->cipher);
417 /* Get cipher name */
418 ret = silc_config_get_token(line, &config->cipher->alg_name);
422 fprintf(stderr, "%s:%d: Cipher name not defined\n",
423 config->filename, pc->linenum);
427 /* Get module name */
428 config->cipher->sim_name = NULL;
429 ret = silc_config_get_token(line, &config->cipher->sim_name);
433 /* Get block length */
434 ret = silc_config_get_token(line, &tmp);
438 fprintf(stderr, "%s:%d: Cipher block length not defined\n",
439 config->filename, pc->linenum);
442 config->cipher->block_len = atoi(tmp);
446 ret = silc_config_get_token(line, &tmp);
450 fprintf(stderr, "%s:%d: Cipher key length not defined\n",
451 config->filename, pc->linenum);
454 config->cipher->key_len = atoi(tmp);
458 checkmask |= (1L << pc->section->type);
461 case SILC_CONFIG_SERVER_SECTION_TYPE_PKCS:
463 SILC_SERVER_CONFIG_LIST_ALLOC(config->pkcs);
466 ret = silc_config_get_token(line, &config->pkcs->alg_name);
470 fprintf(stderr, "%s:%d: PKCS name not defined\n",
471 config->filename, pc->linenum);
476 ret = silc_config_get_token(line, &tmp);
480 fprintf(stderr, "%s:%d: PKCS key length not defined\n",
481 config->filename, pc->linenum);
484 config->pkcs->key_len = atoi(tmp);
488 checkmask |= (1L << pc->section->type);
491 case SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION:
493 SILC_SERVER_CONFIG_LIST_ALLOC(config->hash_func);
495 /* Get Hash function name */
496 ret = silc_config_get_token(line, &config->hash_func->alg_name);
500 fprintf(stderr, "%s:%d: Hash function name not defined\n",
501 config->filename, pc->linenum);
505 /* Get Hash function module name */
506 config->hash_func->sim_name = NULL;
507 ret = silc_config_get_token(line, &config->hash_func->sim_name);
511 /* Get block length */
512 ret = silc_config_get_token(line, &tmp);
516 fprintf(stderr, "%s:%d: Hash function block length not defined\n",
517 config->filename, pc->linenum);
520 config->hash_func->block_len = atoi(tmp);
523 /* Get hash length */
524 ret = silc_config_get_token(line, &tmp);
528 fprintf(stderr, "%s:%d: Hash function hash length not defined\n",
529 config->filename, pc->linenum);
532 config->hash_func->key_len = atoi(tmp);
536 checkmask |= (1L << pc->section->type);
539 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO:
541 if (!config->server_info)
542 config->server_info = silc_calloc(1, sizeof(*config->server_info));
544 /* Get server name */
545 ret = silc_config_get_token(line, &config->server_info->server_name);
549 /* Server name not defined */
554 ret = silc_config_get_token(line, &config->server_info->server_ip);
558 /* Server IP not defined */
562 /* Get server location */
563 ret = silc_config_get_token(line, &config->server_info->location);
567 /* Get server port */
568 /* XXX: Need port here??? */
569 ret = silc_config_get_token(line, &tmp);
573 /* Port not defined */
576 config->server_info->port = atoi(tmp);
580 checkmask |= (1L << pc->section->type);
583 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO:
585 if (!config->admin_info)
586 config->admin_info = silc_calloc(1, sizeof(*config->admin_info));
589 ret = silc_config_get_token(line, &config->admin_info->location);
593 /* Get server type */
594 ret = silc_config_get_token(line, &config->admin_info->server_type);
598 /* Get admins name */
599 ret = silc_config_get_token(line, &config->admin_info->admin_name);
603 /* Get admins email address */
604 ret = silc_config_get_token(line, &config->admin_info->admin_email);
609 checkmask |= (1L << pc->section->type);
612 case SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT:
614 SILC_SERVER_CONFIG_LIST_ALLOC(config->listen_port);
617 ret = silc_config_get_token(line, &config->listen_port->host);
622 ret = silc_config_get_token(line, &config->listen_port->remote_ip);
627 ret = silc_config_get_token(line, &tmp);
632 config->listen_port->port = 0;
634 config->listen_port->port = atoi(tmp);
639 checkmask |= (1L << pc->section->type);
642 case SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY:
644 if (!config->identity)
645 config->identity = silc_calloc(1, sizeof(*config->identity));
648 ret = silc_config_get_token(line, &config->identity->user);
652 ret = silc_config_get_token(line, &config->identity->group);
657 checkmask |= (1L << pc->section->type);
659 case SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS:
661 SILC_SERVER_CONFIG_LIST_ALLOC(config->conn_class);
663 /* Get class number */
664 ret = silc_config_get_token(line, &tmp);
668 /* Class number not defined */
671 config->conn_class->class = atoi(tmp);
674 /* Get ping frequency */
675 ret = silc_config_get_token(line, &tmp);
678 config->conn_class->ping_freq = atoi(tmp);
681 /* Get connect frequency */
682 ret = silc_config_get_token(line, &tmp);
685 config->conn_class->connect_freq = atoi(tmp);
689 ret = silc_config_get_token(line, &tmp);
692 config->conn_class->max_links = atoi(tmp);
696 checkmask |= (1L << pc->section->type);
699 case SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING:
701 SILC_SERVER_CONFIG_LIST_ALLOC(config->logging);
703 /* Get log section type and check it */
704 ret = silc_config_get_token(line, &config->logging->logtype);
708 fprintf(stderr, "%s:%d: Log file section not defined\n",
709 config->filename, pc->linenum);
712 if (strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_INFO)
713 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_WARNING)
714 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_ERROR)
715 && strcmp(config->logging->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
716 fprintf(stderr, "%s:%d: Unknown log file section '%s'\n",
717 config->filename, pc->linenum, config->logging->logtype);
721 /* Get log filename */
722 ret = silc_config_get_token(line, &config->logging->filename);
726 fprintf(stderr, "%s:%d: Log file name not defined\n",
727 config->filename, pc->linenum);
731 /* Get max byte size */
732 ret = silc_config_get_token(line, &tmp);
736 config->logging->maxsize = atoi(tmp);
741 checkmask |= (1L << pc->section->type);
744 case SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION:
746 SILC_SERVER_CONFIG_LIST_ALLOC(config->clients);
749 ret = silc_config_get_token(line, &config->clients->host);
754 config->clients->host = strdup("*");
756 /* Get authentication method */
757 ret = silc_config_get_token(line, &tmp);
761 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
762 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
763 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
764 config->filename, pc->linenum, tmp);
768 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
769 config->clients->auth_meth = SILC_AUTH_PASSWORD;
771 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
772 config->clients->auth_meth = SILC_AUTH_PUBLIC_KEY;
777 /* Get authentication data */
778 ret = silc_config_get_token(line, &config->clients->auth_data);
783 config->clients->host = strdup("*");
786 ret = silc_config_get_token(line, &tmp);
790 config->clients->port = atoi(tmp);
794 /* Get class number */
795 ret = silc_config_get_token(line, &tmp);
799 config->clients->class = atoi(tmp);
804 checkmask |= (1L << pc->section->type);
807 case SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION:
809 SILC_SERVER_CONFIG_LIST_ALLOC(config->servers);
812 ret = silc_config_get_token(line, &config->servers->host);
817 config->servers->host = strdup("*");
819 /* Get authentication method */
820 ret = silc_config_get_token(line, &tmp);
824 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
825 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
826 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
827 config->filename, pc->linenum, tmp);
831 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
832 config->servers->auth_meth = SILC_AUTH_PASSWORD;
834 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
835 config->servers->auth_meth = SILC_AUTH_PUBLIC_KEY;
840 /* Get authentication data */
841 ret = silc_config_get_token(line, &config->servers->auth_data);
846 ret = silc_config_get_token(line, &tmp);
850 config->servers->port = atoi(tmp);
855 ret = silc_config_get_token(line, &config->servers->version);
859 /* Get class number */
860 ret = silc_config_get_token(line, &tmp);
864 config->servers->class = atoi(tmp);
869 checkmask |= (1L << pc->section->type);
872 case SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION:
874 SILC_SERVER_CONFIG_LIST_ALLOC(config->routers);
877 ret = silc_config_get_token(line, &config->routers->host);
882 // config->routers->host = strdup("*");
884 /* Get authentication method */
885 ret = silc_config_get_token(line, &tmp);
889 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
890 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
891 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
892 config->filename, pc->linenum, tmp);
896 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
897 config->routers->auth_meth = SILC_AUTH_PASSWORD;
899 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
900 config->routers->auth_meth = SILC_AUTH_PUBLIC_KEY;
905 /* Get authentication data */
906 ret = silc_config_get_token(line, &config->routers->auth_data);
911 ret = silc_config_get_token(line, &tmp);
915 config->routers->port = atoi(tmp);
920 ret = silc_config_get_token(line, &config->routers->version);
924 /* Get class number */
925 ret = silc_config_get_token(line, &tmp);
929 config->routers->class = atoi(tmp);
933 /* Get whether we are initiator or not */
934 ret = silc_config_get_token(line, &tmp);
938 config->routers->initiator = atoi(tmp);
939 if (config->routers->initiator != 0)
940 config->routers->initiator = TRUE;
945 checkmask |= (1L << pc->section->type);
948 case SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION:
950 SILC_SERVER_CONFIG_LIST_ALLOC(config->admins);
953 ret = silc_config_get_token(line, &config->admins->host);
958 config->admins->host = strdup("*");
960 /* Get authentication method */
961 ret = silc_config_get_token(line, &tmp);
965 if (strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD) &&
966 strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY)) {
967 fprintf(stderr, "%s:%d: Unknown authentication method '%s'\n",
968 config->filename, pc->linenum, tmp);
972 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PASSWD))
973 config->admins->auth_meth = SILC_AUTH_PASSWORD;
975 if (!strcmp(tmp, SILC_CONFIG_SERVER_AUTH_METH_PUBKEY))
976 config->admins->auth_meth = SILC_AUTH_PUBLIC_KEY;
981 /* Get authentication data */
982 ret = silc_config_get_token(line, &config->admins->auth_data);
987 ret = silc_config_get_token(line, &config->admins->nickname);
991 /* Get class number */
992 ret = silc_config_get_token(line, &tmp);
996 config->admins->class = atoi(tmp);
1001 checkmask |= (1L << pc->section->type);
1004 case SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION:
1005 /* Not implemented yet */
1009 case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
1010 /* Not implemented yet */
1014 case SILC_CONFIG_SERVER_SECTION_TYPE_MOTD:
1017 config->motd = silc_calloc(1, sizeof(*config->motd));
1020 ret = silc_config_get_token(line, &config->motd->motd_file);
1025 checkmask |= (1L << pc->section->type);
1028 case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
1034 /* Check for error */
1035 if (check == FALSE) {
1036 /* Line could not be parsed */
1037 fprintf(stderr, "%s:%d: Parse error\n", config->filename, pc->linenum);
1043 // silc_free(pc->prev);
1050 /* Check that all mandatory sections really were found. If not, the server
1051 cannot function and we return error. */
1052 ret = silc_config_server_check_sections(checkmask);
1058 /* Before returning all the lists in the config object must be set
1059 to their first values (the last value is first here). */
1060 while (config->cipher && config->cipher->prev)
1061 config->cipher = config->cipher->prev;
1062 while (config->pkcs && config->pkcs->prev)
1063 config->pkcs = config->pkcs->prev;
1064 while (config->hash_func && config->hash_func->prev)
1065 config->hash_func = config->hash_func->prev;
1066 while (config->listen_port && config->listen_port->prev)
1067 config->listen_port = config->listen_port->prev;
1068 while (config->logging && config->logging->prev)
1069 config->logging = config->logging->prev;
1070 while (config->conn_class && config->conn_class->prev)
1071 config->conn_class = config->conn_class->prev;
1072 while (config->clients && config->clients->prev)
1073 config->clients = config->clients->prev;
1074 while (config->servers && config->servers->prev)
1075 config->servers = config->servers->prev;
1076 while (config->routers && config->routers->prev)
1077 config->routers = config->routers->prev;
1079 SILC_LOG_DEBUG(("Done"));
1084 /* This function checks that the mask sent as argument includes all the
1085 sections that are mandatory in SILC server. */
1087 int silc_config_server_check_sections(unsigned int checkmask)
1089 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
1093 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO))) {
1097 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT))) {
1101 if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
1106 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION))) {
1111 & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION))) {
1119 /* Sets log files where log messages is saved by the server. */
1121 void silc_config_server_setlogfiles(SilcConfigServer config)
1123 SilcConfigServerSectionLogging *log;
1124 char *info, *warning, *error, *fatal;
1125 unsigned int info_size, warning_size, error_size, fatal_size;
1127 SILC_LOG_DEBUG(("Setting configured log file names"));
1129 /* Set default files before checking configuration */
1130 info = SILC_LOG_FILE_INFO;
1131 warning = SILC_LOG_FILE_WARNING;
1132 error = SILC_LOG_FILE_ERROR;
1133 fatal = SILC_LOG_FILE_FATAL;
1139 log = config->logging;
1141 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_INFO)) {
1142 info = log->filename;
1143 info_size = log->maxsize;
1145 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_WARNING)) {
1146 warning = log->filename;
1147 warning_size = log->maxsize;
1149 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_ERROR)) {
1150 error = log->filename;
1151 error_size = log->maxsize;
1153 if (!strcmp(log->logtype, SILC_CONFIG_SERVER_LF_FATAL)) {
1154 fatal = log->filename;
1155 fatal_size = log->maxsize;
1161 silc_log_set_files(info, info_size, warning, warning_size,
1162 error, error_size, fatal, fatal_size);
1165 /* Registers configured ciphers. These can then be allocated by the
1166 server when needed. */
1168 void silc_config_server_register_ciphers(SilcConfigServer config)
1170 SilcConfigServerSectionAlg *alg;
1171 SilcServer server = (SilcServer)config->server;
1173 SILC_LOG_DEBUG(("Registering configured ciphers"));
1175 alg = config->cipher;
1178 if (!alg->sim_name) {
1179 /* Crypto module is supposed to be built in. Nothing to be done
1180 here except to test that the cipher really is built in. */
1181 SilcCipher tmp = NULL;
1183 if (silc_cipher_alloc(alg->alg_name, &tmp) == FALSE) {
1184 SILC_LOG_ERROR(("Unsupported cipher `%s'", alg->alg_name));
1185 silc_server_stop(server);
1188 silc_cipher_free(tmp);
1192 /* Load (try at least) the crypto SIM module */
1193 SilcCipherObject cipher;
1194 SilcSimContext *sim;
1196 memset(&cipher, 0, sizeof(cipher));
1197 cipher.name = alg->alg_name;
1198 cipher.block_len = alg->block_len;
1199 cipher.key_len = alg->key_len * 8;
1201 sim = silc_sim_alloc();
1202 sim->type = SILC_SIM_CIPHER;
1203 sim->libname = alg->sim_name;
1205 if ((silc_sim_load(sim))) {
1207 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1208 SILC_CIPHER_SIM_SET_KEY));
1209 SILC_LOG_DEBUG(("set_key=%p", cipher.set_key));
1210 cipher.set_key_with_string =
1211 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1212 SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
1213 SILC_LOG_DEBUG(("set_key_with_string=%p", cipher.set_key_with_string));
1215 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1216 SILC_CIPHER_SIM_ENCRYPT_CBC));
1217 SILC_LOG_DEBUG(("encrypt_cbc=%p", cipher.encrypt));
1219 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1220 SILC_CIPHER_SIM_DECRYPT_CBC));
1221 SILC_LOG_DEBUG(("decrypt_cbc=%p", cipher.decrypt));
1222 cipher.context_len =
1223 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1224 SILC_CIPHER_SIM_CONTEXT_LEN));
1225 SILC_LOG_DEBUG(("context_len=%p", cipher.context_len));
1227 /* Put the SIM to the list of all SIM's in server */
1228 silc_dlist_add(server->sim, sim);
1230 SILC_LOG_ERROR(("Error configuring ciphers"));
1231 silc_server_stop(server);
1235 /* Register the cipher */
1236 silc_cipher_register(&cipher);
1244 /* Registers configured PKCS's. */
1245 /* XXX: This really doesn't do anything now since we have statically
1246 registered our PKCS's. This should be implemented when PKCS works
1247 as SIM's. This checks now only that the PKCS user requested is
1248 really out there. */
1250 void silc_config_server_register_pkcs(SilcConfigServer config)
1252 SilcConfigServerSectionAlg *alg = config->pkcs;
1253 SilcServer server = (SilcServer)config->server;
1254 SilcPKCS tmp = NULL;
1256 SILC_LOG_DEBUG(("Registering configured PKCS"));
1260 if (silc_pkcs_alloc(alg->alg_name, &tmp) == FALSE) {
1261 SILC_LOG_ERROR(("Unsupported PKCS `%s'", alg->alg_name));
1262 silc_server_stop(server);
1271 /* Registers configured hash functions. These can then be allocated by the
1272 server when needed. */
1274 void silc_config_server_register_hashfuncs(SilcConfigServer config)
1276 SilcConfigServerSectionAlg *alg;
1277 SilcServer server = (SilcServer)config->server;
1279 SILC_LOG_DEBUG(("Registering configured hash functions"));
1281 alg = config->hash_func;
1284 if (!alg->sim_name) {
1285 /* Hash module is supposed to be built in. Nothing to be done
1286 here except to test that the hash function really is built in. */
1287 SilcHash tmp = NULL;
1289 if (silc_hash_alloc(alg->alg_name, &tmp) == FALSE) {
1290 SILC_LOG_ERROR(("Unsupported hash function `%s'", alg->alg_name));
1291 silc_server_stop(server);
1298 /* Load (try at least) the hash SIM module */
1299 SilcHashObject hash;
1300 SilcSimContext *sim;
1302 memset(&hash, 0, sizeof(hash));
1303 hash.name = alg->alg_name;
1304 hash.block_len = alg->block_len;
1305 hash.hash_len = alg->key_len;
1307 sim = silc_sim_alloc();
1308 sim->type = SILC_SIM_HASH;
1309 sim->libname = alg->sim_name;
1311 if ((silc_sim_load(sim))) {
1313 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1314 SILC_HASH_SIM_INIT));
1315 SILC_LOG_DEBUG(("init=%p", hash.init));
1317 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1318 SILC_HASH_SIM_UPDATE));
1319 SILC_LOG_DEBUG(("update=%p", hash.update));
1321 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1322 SILC_HASH_SIM_FINAL));
1323 SILC_LOG_DEBUG(("final=%p", hash.final));
1325 silc_sim_getsym(sim, silc_sim_symname(alg->alg_name,
1326 SILC_HASH_SIM_CONTEXT_LEN));
1327 SILC_LOG_DEBUG(("context_len=%p", hash.context_len));
1329 /* Put the SIM to the table of all SIM's in server */
1330 silc_dlist_add(server->sim, sim);
1332 SILC_LOG_ERROR(("Error configuring hash functions"));
1333 silc_server_stop(server);
1337 /* Register the cipher */
1338 silc_hash_register(&hash);
1346 /* Returns client authentication information from server configuration
1347 by host (name or ip). */
1349 SilcConfigServerSectionClientConnection *
1350 silc_config_server_find_client_conn(SilcConfigServer config,
1351 char *host, int port)
1354 SilcConfigServerSectionClientConnection *client = NULL;
1359 if (!config->clients)
1362 client = config->clients;
1364 for (i = 0; client; i++) {
1365 if (silc_string_compare(client->host, host))
1367 client = client->next;
1376 /* Returns server connection info from server configuartion by host
1379 SilcConfigServerSectionServerConnection *
1380 silc_config_server_find_server_conn(SilcConfigServer config,
1381 char *host, int port)
1384 SilcConfigServerSectionServerConnection *serv = NULL;
1389 if (!config->servers)
1392 serv = config->servers;
1393 for (i = 0; serv; i++) {
1394 if (silc_string_compare(serv->host, host))
1405 /* Returns router connection info from server configuartion by
1406 host (name or ip). */
1408 SilcConfigServerSectionServerConnection *
1409 silc_config_server_find_router_conn(SilcConfigServer config,
1410 char *host, int port)
1413 SilcConfigServerSectionServerConnection *serv = NULL;
1418 if (!config->routers)
1421 serv = config->routers;
1422 for (i = 0; serv; i++) {
1423 if (silc_string_compare(serv->host, host))
1434 /* Prints out example configuration file with default built in
1435 configuration values. */
1437 void silc_config_server_print()
1443 # Automatically generated example SILCd configuration file with default\n\
1444 # built in values. Use this as a guide to configure your SILCd configuration\n\
1445 # file for your system. For detailed description of different configuration\n\
1446 # sections refer to silcd(8) manual page.\n\
1461 +lassi.kuo.fi.ssh.com:10.2.1.6:Kuopio, Finland:1333
1464 +Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
1467 +10.2.1.6:10.2.1.6:1333
1470 +infologfile:silcd.log:10000
1471 #+warninglogfile:/var/log/silcd_warning.log:10000
1472 #+errorlogfile:ERROR.log:10000
1473 #+fatallogfile:/var/log/silcd_error.log:
1480 +10.2.1.199:priikone:333:1
1483 +10.2.1.199:priikone:priikone:1
1493 fprintf(stdout, "%s\n", buf);