updates.
[silc.git] / apps / silcd / serverconfig.c
index b4c264b34d9472bce2211e1dd1c81c73042352ac..cd5a0d3749365fd362d8fefb6d00810fe2395ca9 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Johnny Mnemonic <johnny@themnemonic.org>
 
-  Copyright (C) 1997 - 2002 Johnny Mnemonic
+  Copyright (C) 1997 - 2002 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -113,18 +113,26 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
 {
   if (auth_meth == SILC_AUTH_PASSWORD) {
     /* p is a plain text password */
-    if (auth_data)
-      *auth_data = (void *) strdup(p);
-    if (auth_data_len)
-      *auth_data_len = (SilcUInt32) strlen(p);
+    if (auth_data && auth_data_len) {
+      if (!silc_utf8_valid(p, strlen(p))) {
+       *auth_data_len = silc_utf8_encoded_len(p, strlen(p), 0);
+       *auth_data = silc_calloc(*auth_data_len, sizeof(unsigned char));
+       silc_utf8_encode(p, strlen(p), SILC_STRING_ASCII, *auth_data,
+                        *auth_data_len);
+      } else {
+       *auth_data = (void *) strdup(p);
+       *auth_data_len = (SilcUInt32) strlen(p);
+      }
+    }
   } else if (auth_meth == SILC_AUTH_PUBLIC_KEY) {
     /* p is a public key file name */
     SilcPublicKey public_key;
 
     if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_PEM))
       if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_BIN)) {
-       SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line %lu: "
-                              "Could not load public key file!\n", line));
+       SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line "
+                              "%lu: Could not load public key file!\n", 
+                              line));
        return FALSE;
       }
 
@@ -1201,6 +1209,7 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
 
   /* alloc a config object */
   config_new = silc_calloc(1, sizeof(*config_new));
+  config_new->refcount = 1;
   if (!config_new)
     return NULL;
 
@@ -1257,7 +1266,6 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
   /* Set default to configuration parameters */
   silc_server_config_set_defaults(config_new);
 
-  config_new->refcount = 1;
   return config_new;
 }
 
@@ -1270,7 +1278,7 @@ void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
     config->refcount++;
     ref->config = config;
     ref->ref_ptr = ref_ptr;
-    SILC_LOG_DEBUG(("Referencing config [%p] refcnt %hu->%hu", config,
+    SILC_LOG_DEBUG(("Referencing config [%p] refcnt %d->%d", config,
                    config->refcount - 1, config->refcount));
   }
 }
@@ -1291,7 +1299,7 @@ void silc_server_config_destroy(SilcServerConfig config)
   void *tmp;
 
   config->refcount--;
-  SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %hu->%hu", config,
+  SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %d->%d", config,
                  config->refcount + 1, config->refcount));
   if (config->refcount > 0)
     return;