updates. New data types.
[silc.git] / apps / silcd / serverconfig.c
index cc51b89b0dab976c7dec9605abfd5a5d12bb55de..f25206d6492dbe9b0211c976084bd7e467e61b8c 100644 (file)
@@ -53,8 +53,6 @@ SilcServerConfigSection silc_server_config_sections[] = {
     SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, 5 },
   { "[DenyConnection]", 
     SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 4 },
-  { "[RedirectClient]", 
-    SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT, 2 },
   { "[motd]", 
     SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
   
@@ -117,7 +115,6 @@ void silc_server_config_free(SilcServerConfig config)
     silc_free(config->servers);
     silc_free(config->routers);
     silc_free(config->denied);
-    silc_free(config->redirect);
     silc_free(config->motd);
     silc_free(config);
   }
@@ -132,8 +129,7 @@ void silc_server_config_free(SilcServerConfig config)
 int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer, 
                             SilcServerConfigParse *return_config)
 {
-  int i, begin;
-  unsigned int linenum;
+  int i, begin, linenum;
   char line[1024], *cp;
   SilcServerConfigSection *cptr = NULL;
   SilcServerConfigParse parse = *return_config, first = NULL;
@@ -250,7 +246,7 @@ int silc_server_config_parse_lines(SilcServerConfig config,
                                   SilcServerConfigParse parse_config)
 {
   int ret, check = FALSE;
-  unsigned int checkmask;
+  uint32 checkmask;
   char *tmp;
   SilcServerConfigParse pc = parse_config;
   SilcBuffer line;
@@ -682,12 +678,30 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       }
 
       /* Get authentication data */
-      ret = silc_config_get_token(line, &config->clients->auth_data);
+      ret = silc_config_get_token(line, (char **)&config->clients->auth_data);
       if (ret < 0)
        break;
-      if (ret == 0)
-       /* Any host */
-       config->clients->host = strdup("*");
+
+      if (config->clients->auth_meth == SILC_AUTH_PASSWORD) {
+       config->clients->auth_data_len = strlen(config->clients->auth_data);
+      } else if (config->clients->auth_meth == SILC_AUTH_PUBLIC_KEY) {
+       /* Get the public key */
+       SilcPublicKey public_key;
+
+       if (!silc_pkcs_load_public_key(config->clients->auth_data,
+                                      &public_key, SILC_PKCS_FILE_PEM))
+         if (!silc_pkcs_load_public_key(config->clients->auth_data,
+                                        &public_key, SILC_PKCS_FILE_BIN)) {
+           fprintf(stderr, "%s:%d: Could not load public key file `%s'\n",
+                   config->filename, pc->linenum, 
+                   (char *)config->clients->auth_data);
+           break;
+         }
+
+       silc_free(config->clients->auth_data);
+       config->clients->auth_data = (void *)public_key;
+       config->clients->auth_data_len = 0;
+      }
 
       /* Get port */
       ret = silc_config_get_token(line, &tmp);
@@ -745,10 +759,31 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       }
 
       /* Get authentication data */
-      ret = silc_config_get_token(line, &config->servers->auth_data);
+      ret = silc_config_get_token(line, (char **)&config->servers->auth_data);
       if (ret < 0)
        break;
 
+      if (config->servers->auth_meth == SILC_AUTH_PASSWORD) {
+       config->servers->auth_data_len = strlen(config->servers->auth_data);
+      } else if (config->servers->auth_meth == SILC_AUTH_PUBLIC_KEY) {
+       /* Get the public key */
+       SilcPublicKey public_key;
+
+       if (!silc_pkcs_load_public_key(config->servers->auth_data,
+                                      &public_key, SILC_PKCS_FILE_PEM))
+         if (!silc_pkcs_load_public_key(config->servers->auth_data,
+                                        &public_key, SILC_PKCS_FILE_BIN)) {
+           fprintf(stderr, "%s:%d: Could not load public key file `%s'\n",
+                   config->filename, pc->linenum, 
+                   (char *)config->servers->auth_data);
+           break;
+         }
+
+       silc_free(config->servers->auth_data);
+       config->servers->auth_data = (void *)public_key;
+       config->servers->auth_data_len = 0;
+      }
+
       /* Get port */
       ret = silc_config_get_token(line, &tmp);
       if (ret < 0)
@@ -810,10 +845,31 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       }
 
       /* Get authentication data */
-      ret = silc_config_get_token(line, &config->routers->auth_data);
+      ret = silc_config_get_token(line, (char **)&config->routers->auth_data);
       if (ret < 0)
        break;
 
+      if (config->routers->auth_meth == SILC_AUTH_PASSWORD) {
+       config->routers->auth_data_len = strlen(config->routers->auth_data);
+      } else if (config->routers->auth_meth == SILC_AUTH_PUBLIC_KEY) {
+       /* Get the public key */
+       SilcPublicKey public_key;
+
+       if (!silc_pkcs_load_public_key(config->routers->auth_data,
+                                      &public_key, SILC_PKCS_FILE_PEM))
+         if (!silc_pkcs_load_public_key(config->routers->auth_data,
+                                        &public_key, SILC_PKCS_FILE_BIN)) {
+           fprintf(stderr, "%s:%d: Could not load public key file `%s'\n",
+                   config->filename, pc->linenum, 
+                   (char *)config->routers->auth_data);
+           break;
+         }
+
+       silc_free(config->routers->auth_data);
+       config->routers->auth_data = (void *)public_key;
+       config->routers->auth_data_len = 0;
+      }
+
       /* Get port */
       ret = silc_config_get_token(line, &tmp);
       if (ret < 0)
@@ -902,10 +958,31 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       }
 
       /* Get authentication data */
-      ret = silc_config_get_token(line, &config->admins->auth_data);
+      ret = silc_config_get_token(line, (char **)&config->admins->auth_data);
       if (ret < 0)
        break;
 
+      if (config->admins->auth_meth == SILC_AUTH_PASSWORD) {
+       config->admins->auth_data_len = strlen(config->admins->auth_data);
+      } else if (config->admins->auth_meth == SILC_AUTH_PUBLIC_KEY) {
+       /* Get the public key */
+       SilcPublicKey public_key;
+
+       if (!silc_pkcs_load_public_key(config->admins->auth_data,
+                                      &public_key, SILC_PKCS_FILE_PEM))
+         if (!silc_pkcs_load_public_key(config->admins->auth_data,
+                                        &public_key, SILC_PKCS_FILE_BIN)) {
+           fprintf(stderr, "%s:%d: Could not load public key file `%s'\n",
+                   config->filename, pc->linenum, 
+                   (char *)config->admins->auth_data);
+           break;
+         }
+
+       silc_free(config->admins->auth_data);
+       config->admins->auth_data = (void *)public_key;
+       config->admins->auth_data_len = 0;
+      }
+
       check = TRUE;
       checkmask |= (1L << pc->section->type);
       break;
@@ -915,11 +992,6 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       check = TRUE;
       break;
 
-    case SILC_CONFIG_SERVER_SECTION_TYPE_REDIRECT_CLIENT:
-      /* Not implemented yet */
-      check = TRUE;
-      break;
-
     case SILC_CONFIG_SERVER_SECTION_TYPE_MOTD:
 
       if (!config->motd)
@@ -948,9 +1020,6 @@ int silc_server_config_parse_lines(SilcServerConfig config,
     }
 
     pc = pc->next;
-    /* XXXX */
-    //    silc_free(pc->prev);
-    //    pc->prev = NULL;
   }
 
   if (check == FALSE)
@@ -995,7 +1064,7 @@ int silc_server_config_parse_lines(SilcServerConfig config,
 /* This function checks that the mask sent as argument includes all the 
    sections that are mandatory in SILC server. */
 
-int silc_server_config_check_sections(unsigned int checkmask)
+int silc_server_config_check_sections(uint32 checkmask)
 {
   if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO))) {
     
@@ -1009,7 +1078,8 @@ int silc_server_config_check_sections(unsigned int checkmask)
     
     return FALSE;
   }
-  if (!(checkmask & (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
+  if (!(checkmask & 
+       (1L << SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION))) {
     
     return FALSE;
   }
@@ -1033,7 +1103,7 @@ void silc_server_config_setlogfiles(SilcServerConfig config)
 {
   SilcServerConfigSectionLogging *log;
   char *info, *warning, *error, *fatal;
-  unsigned int info_size, warning_size, error_size, fatal_size;
+  uint32 info_size, warning_size, error_size, fatal_size;
 
   SILC_LOG_DEBUG(("Setting configured log file names"));
 
@@ -1403,7 +1473,7 @@ silc_server_config_find_admin(SilcServerConfig config,
     host = "*";
   if (!username)
     username = "*";
-  if (nickname)
+  if (!nickname)
     nickname = "*";
 
   admin = config->admins;
@@ -1478,7 +1548,6 @@ void silc_server_config_print()
 <RouterConnection>
 
 <DenyConnection>
-<RedirectClient>
   */
 
   fprintf(stdout, "%s\n", buf);