updates.
[silc.git] / apps / silcd / silcd.c
index 3cef69aa78dfacdb8d409ea5728447b7f79eded2..2e65293e23900cee13f59635329a853457241e57 100644 (file)
 
 #include "serverincludes.h"
 #include "server_internal.h"
-#include "version.h"
+#include "silcversion.h"
 
 /* For now, we'll have this one server context global for this module. */
 static SilcServer silcd;
 
-static void silc_usage();
-static char *silc_server_create_identifier();
+static void silc_usage(void);
+static char *silc_server_create_identifier(void);
 static int
 silc_server_create_key_pair(char *pkcs_name, int bits, char *path,
                            char *identifier,
                            SilcPublicKey *ret_pub_key,
                            SilcPrivateKey *ret_prv_key);
+static void silc_server_create_passphrase(void);
 
 /* Long command line options */
 static struct option long_opts[] =
 {
   { "config-file", 1, NULL, 'f' },
+  { "passphrase", 1, NULL, 'p' },
   { "debug", 1, NULL, 'd' },
   { "help", 0, NULL, 'h' },
   { "foreground", 0, NULL, 'F' },
@@ -67,7 +69,7 @@ static int opt_bits = 1024;
 
 /* Prints out the usage of silc client */
 
-static void silc_usage()
+static void silc_usage(void)
 {
   printf("\
 Usage: silcd [options]\n\
@@ -107,7 +109,7 @@ static void silc_server_checkpid(SilcServer silcd)
   if (silcd->config->server_info->pid_file) {
     int oldpid;
     char *buf;
-    uint32 buf_len;
+    SilcUInt32 buf_len;
 
     SILC_LOG_DEBUG(("Checking for another silcd running"));
     buf = silc_file_readfile(silcd->config->server_info->pid_file, &buf_len);
@@ -119,7 +121,8 @@ static void silc_server_checkpid(SilcServer silcd)
       return;
     kill(oldpid, SIGCHLD); /* this signal does nothing, check if alive */
     if (errno != ESRCH) {
-      fprintf(stderr, "\nI detected another daemon running with the same pid file.\n");
+      fprintf(stderr, "\nI detected another daemon running with the "
+             "same pid file.\n");
       fprintf(stderr, "Please change the config file, or erase the %s\n",
        silcd->config->server_info->pid_file);
       exit(1);
@@ -127,14 +130,20 @@ static void silc_server_checkpid(SilcServer silcd)
   }
 }
 
-static void got_hup(int z)
+static void signal_handler(int sig)
+{
+  /* Mark the signal to be caller after this signal is over. */
+  silc_schedule_signal_call(silcd->schedule, sig);
+}
+
+SILC_TASK_CALLBACK(got_hup)
 {
   /* First, reset all log files (they might have been deleted) */
   silc_log_reset_all();
   silc_log_flush_all();
 }
 
-static void stop_server(int z)
+SILC_TASK_CALLBACK(stop_server)
 {
   /* Stop scheduler, the program will stop eventually after noticing
      that the scheduler is down. */
@@ -150,7 +159,7 @@ int main(int argc, char **argv)
 
   /* Parse command line arguments */
   if (argc > 1) {
-    while ((opt = getopt_long(argc, argv, "cf:d:hFVC:",
+    while ((opt = getopt_long(argc, argv, "f:d:hFVC:",
                              long_opts, &option_index)) != EOF) {
       switch(opt)
        {
@@ -251,12 +260,13 @@ int main(int argc, char **argv)
   sa.sa_flags = 0;
   sigemptyset(&sa.sa_mask);
   sigaction(SIGPIPE, &sa, NULL);
-  sa.sa_handler = got_hup;
+  sa.sa_handler = signal_handler;
   sigaction(SIGHUP, &sa, NULL);
-  sa.sa_handler = stop_server;
   sigaction(SIGTERM, &sa, NULL);
-  sa.sa_handler = stop_server;
   sigaction(SIGINT, &sa, NULL);
+  silc_schedule_signal_register(silcd->schedule, SIGHUP, got_hup, NULL);
+  silc_schedule_signal_register(silcd->schedule, SIGTERM, stop_server, NULL);
+  silc_schedule_signal_register(silcd->schedule, SIGINT, stop_server, NULL);
 
   /* Before running the server, fork to background. */
   if (!foreground)
@@ -291,7 +301,7 @@ int main(int argc, char **argv)
 
 /* Returns identifier string for public key generation. */
 
-static char *silc_server_create_identifier()
+static char *silc_server_create_identifier(void)
 {
   char *username = NULL, *realname = NULL;
   char hostname[256], email[256];
@@ -329,7 +339,7 @@ silc_server_create_key_pair(char *pkcs_name, int bits, char *path,
   SilcPrivateKey prv_key;
   SilcRng rng;
   unsigned char *key;
-  uint32 key_len;
+  SilcUInt32 key_len;
   char pkfile[256], prvfile[256];
 
   if (!pkcs_name || !path)
@@ -357,7 +367,7 @@ silc_server_create_key_pair(char *pkcs_name, int bits, char *path,
 
   /* Generate keys */
   silc_pkcs_alloc(pkcs_name, &pkcs);
-  pkcs->pkcs->init(pkcs->context, bits, rng);
+  silc_pkcs_generate_key(pkcs, bits, rng);
 
   /* Save public key into file */
   key = silc_pkcs_get_public_key(pkcs, &key_len);