updates.
[silc.git] / apps / silcd / serverconfig.c
index cc51b89b0dab976c7dec9605abfd5a5d12bb55de..de77334c9cbf4e5e54fcd783c9fe3c5feb30c86b 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);
   }
@@ -682,12 +679,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 +760,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 +846,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 +959,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 +993,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 +1021,6 @@ int silc_server_config_parse_lines(SilcServerConfig config,
     }
 
     pc = pc->next;
-    /* XXXX */
-    //    silc_free(pc->prev);
-    //    pc->prev = NULL;
   }
 
   if (check == FALSE)
@@ -1009,7 +1079,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;
   }
@@ -1403,7 +1474,7 @@ silc_server_config_find_admin(SilcServerConfig config,
     host = "*";
   if (!username)
     username = "*";
-  if (nickname)
+  if (!nickname)
     nickname = "*";
 
   admin = config->admins;
@@ -1478,7 +1549,6 @@ void silc_server_config_print()
 <RouterConnection>
 
 <DenyConnection>
-<RedirectClient>
   */
 
   fprintf(stdout, "%s\n", buf);