updates.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 14 Nov 2001 14:44:27 +0000 (14:44 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 14 Nov 2001 14:44:27 +0000 (14:44 +0000)
CHANGES
TODO
apps/irssi/src/silc/core/client_ops.c
apps/silcd/command.c
apps/silcd/server.c
apps/silcd/server.h
apps/silcd/serverconfig.c
apps/silcd/serverconfig.h
apps/silcd/silcd.c
lib/silcclient/command_reply.c
lib/silccrypt/silcrng.c

diff --git a/CHANGES b/CHANGES
index 3ad553683b10cbbecba6a2934dcf7519d3bedf20..88ca9bec61e565ca9dadf66e7acd08ded5a0525d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,12 @@ Wed Nov 14 16:22:25 EET 2001  Pekka Riikonen <priikone@silcnet.org>
          to run server on foreground.  A patch by debolaz.
          Affected files silcd/server.c, silcd/silcd.c.
 
+       * Fixed MOTD to return the MOTD file server name.  Affected
+         file silcd/command.c.
+
+       * Added INFO command reply handling to the Irssi SILC Client.
+         Affected file irssi/src/silc/core/client_ops.c.
+
 Wed Nov 14 00:18:08 EET 2001  Pekka Riikonen <priikone@silcnet.org>
 
        * Fixed the silc_idcache_list_* routines to really support
diff --git a/TODO b/TODO
index 168e26521c3cbcfe5043bb0c6cf55bc6610b1871..c631c660f2c5af71ed4afd29e5bcbb9c64a819c0 100644 (file)
--- a/TODO
+++ b/TODO
@@ -41,8 +41,6 @@ TODO/bugs In SILC Client Library
 TODO/bugs In SILC Server
 ========================
 
- o MOTD and INFO does not work with server name.
-
  o After backup resume protocol the TOPIC_SET was not handled correctly
    by all (unknown Channel ID).
 
index 4104b4bdf8606d874b97f4a3136a9fcf6659fbc6..772fb243f089c087ce390608ad9d6ce7c8550692 100644 (file)
@@ -791,6 +791,27 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       }
     }
     break;
+
+  case SILC_COMMAND_INFO:
+    {
+      SilcServerEntry server_entry;
+      char *server_name;
+      char *server_info;
+
+      if (!success)
+       return;
+      
+      server_entry = va_arg(vp, SilcServerEntry);
+      server_name = va_arg(vp, char *);
+      server_info = va_arg(vp, char *);
+
+      if (server_name && server_info )
+       {
+         printtext(server, NULL, MSGLEVEL_CRAP, "Server: %s", server_name);
+         printtext(server, NULL, MSGLEVEL_CRAP, "%s", server_info);
+       }
+    }
+    break;
     
   case SILC_COMMAND_TOPIC:
     {
index f3eab682ae4f142dc51827ce5c2976726b25ccf0..64fa02a22f1021eb648a5cd95f2648bb68ed844f 100644 (file)
@@ -3474,7 +3474,6 @@ SILC_SERVER_CMD_FUNC(motd)
                                                    SILC_STATUS_OK, ident, 2,
                                                    2, idp, idp->len,
                                                    3, motd, motd_len);
-      goto out;
     } else {
       /* No motd */
       packet = silc_command_reply_payload_encode_va(SILC_COMMAND_MOTD,
index 2d76a24a55601af18f326db26893ab2c1f70899c..6a76301feee77cb2e65959ee25fefb01a5eb11a4 100644 (file)
@@ -356,19 +356,42 @@ int silc_server_init(SilcServer server)
   return FALSE;
 }
 
-/* Fork server to background and set gid+uid to non-root.
-   Silcd will not run as root, so trying to set either user or group to
-   root will cause silcd to exit. */
+/* Fork server to background and set gid+uid to non-root */
 
 void silc_server_daemonise(SilcServer server)
+{
+  int i;
+
+  i = fork ();
+
+  if (i) {
+    if (i > 0) {
+      if (geteuid())
+        SILC_LOG_DEBUG(("Server started as user"));
+      else
+        SILC_LOG_DEBUG(("Server started as root. Dropping privileges."));
+
+      SILC_LOG_DEBUG(("Forking SILC server to background"));
+      exit(0);
+    } else {
+      SILC_LOG_DEBUG(("fork() failed, cannot proceed"));
+      exit(1);
+    }
+  }
+  setsid();
+}
+
+/* Drop root privligies. If this cannot be done, die. */
+
+void silc_server_drop(SilcServer server)
 {
   /* Are we executing silcd as root or a regular user? */
-  if (geteuid()==0) {
-    
+  if (!geteuid()) {
+
     struct passwd *pw;
     struct group *gr;
     char *user, *group;
-    
+
     if (!server->config->identity || !server->config->identity->user || 
        !server->config->identity->group) {
       fprintf(stderr, "Error:"
@@ -378,11 +401,11 @@ void silc_server_daemonise(SilcServer server)
        "\tthe server as non-root user.\n");
       exit(1);
     }
-    
+
     /* Get the values given for user and group in configuration file */
     user=server->config->identity->user;
     group=server->config->identity->group;
-    
+
     /* Check whether the user/group information is text */ 
     if (atoi(user)!=0 || atoi(group)!=0) {
       SILC_LOG_DEBUG(("Invalid user and/or group information"));
@@ -391,14 +414,14 @@ void silc_server_daemonise(SilcServer server)
       fprintf(stderr, "Please assign them as names, not numbers\n");
       exit(1);
     }
-    
+
     /* Catch the nasty incident of string "0" returning 0 from atoi */
     if (strcmp("0", user)==0 || strcmp("0", group)==0) {
       SILC_LOG_DEBUG(("User and/or group configured to 0. Unacceptable"));
       fprintf(stderr, "User and/or group configured to 0. Exiting\n");
       exit(1);
     }
-    
+
     pw=getpwnam(user);
     gr=getgrnam(group);
 
@@ -411,7 +434,7 @@ void silc_server_daemonise(SilcServer server)
       fprintf(stderr, "No such group %s found\n", group);
       exit(1);
     }
-    
+
     /* Check whether user and/or group is set to root. If yes, exit
        immediately. Otherwise, setgid and setuid server to user.group */
     if (gr->gr_gid==0 || pw->pw_uid==0) {
@@ -422,14 +445,6 @@ void silc_server_daemonise(SilcServer server)
        "\tthe server as non-root user.\n");
       exit(1);
     } else {
-      /* Fork server to background, making it a daemon */
-      if (fork()) {
-        SILC_LOG_DEBUG(("Server started as root. Dropping privileges."));
-        SILC_LOG_DEBUG(("Forking SILC server to background"));
-        exit(0);
-      } 
-      setsid();
-      
       SILC_LOG_DEBUG(("Changing to group %s", group));
       if(setgid(gr->gr_gid)==0) {
         SILC_LOG_DEBUG(("Setgid to %s", group));
@@ -449,14 +464,6 @@ void silc_server_daemonise(SilcServer server)
         exit(1);
       }
     }
-  } else {
-    /* Fork server to background, making it a daemon */
-    if (fork()) {
-      SILC_LOG_DEBUG(("Server started as user")); 
-      SILC_LOG_DEBUG(("Forking SILC server to background"));
-      exit(0);
-    }
-    setsid();
   }
 }
 
index 1020a81a81f5be67ffdb01e851bc7a268405fcc5..8ea3293b26257cd091c85d04172b65fa594ec84d 100644 (file)
@@ -121,6 +121,7 @@ int silc_server_alloc(SilcServer *new_server);
 void silc_server_free(SilcServer server);
 int silc_server_init(SilcServer server);
 void silc_server_daemonise(SilcServer server);
+void silc_server_drop(SilcServer server);
 void silc_server_run(SilcServer server);
 void silc_server_stop(SilcServer server);
 void silc_server_start_key_exchange(SilcServer server,
index 5aaec48955776bd5b3eaf0a85ef29d6d2e7fa163..d91db49b87ac9fcf97c0912db888bb7544192b28 100644 (file)
@@ -57,6 +57,8 @@ SilcServerConfigSection silc_server_config_sections[] = {
     SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, 3 },
   { "[motd]", 
     SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, 1 },
+  { "[pid]",
+    SILC_CONFIG_SERVER_SECTION_TYPE_PID, 1},
   
   { NULL, SILC_CONFIG_SERVER_SECTION_TYPE_NONE, 0 }
 };
@@ -121,6 +123,7 @@ void silc_server_config_free(SilcServerConfig config)
     silc_free(config->routers);
     silc_free(config->denied);
     silc_free(config->motd);
+    silc_free(config->pidfile);
     silc_free(config);
   }
 }
@@ -1107,6 +1110,19 @@ int silc_server_config_parse_lines(SilcServerConfig config,
       checkmask |= (1L << pc->section->type);
       break;
 
+    case SILC_CONFIG_SERVER_SECTION_TYPE_PID:
+
+       if (!config->pidfile)
+          config->pidfile = silc_calloc(1, sizeof(*config->pidfile));
+          
+       ret = silc_config_get_token(line, &config->pidfile->pid_file);
+       if (ret < 0)
+          break;
+          
+       check = TRUE;
+       checkmask |= (1L << pc->section->type);
+       break;
+
     case SILC_CONFIG_SERVER_SECTION_TYPE_NONE:
     default:
       /* Error */
index 1df1e95a4115dac69818d6dc3a5513476e8af58b..ef284fb01b1707d415891a73aa6bb85d1a4b78b7 100644 (file)
@@ -154,6 +154,11 @@ typedef struct {
   char *motd_file;
 } SilcServerConfigSectionMotd;
 
+/* holds pid file */
+typedef struct {
+   char *pid_file;
+} SilcServerConfigSectionPid;
+
 /* 
    SILC Server Config object. 
 
@@ -186,6 +191,7 @@ typedef struct {
   SilcServerConfigSectionAdminConnection *admins;
   SilcServerConfigSectionDenyConnection *denied;
   SilcServerConfigSectionMotd *motd;
+  SilcServerConfigSectionPid *pidfile;
 } SilcServerConfigObject;
 
 typedef SilcServerConfigObject *SilcServerConfig;
@@ -210,6 +216,7 @@ typedef enum {
   SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION,
   SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION,
   SILC_CONFIG_SERVER_SECTION_TYPE_MOTD,
+  SILC_CONFIG_SERVER_SECTION_TYPE_PID,
 } SilcServerConfigSectionType;
 
 /* SILC Configuration Section structure. */
index bfb50ca7082e2ee95e5fda05e75fee920a528be5..085a2522faa1c55093b0c99e68f768f299839be9 100644 (file)
@@ -43,6 +43,7 @@ static struct option long_opts[] =
   { "config-file", 1, NULL, 'f' },
   { "debug", 1, NULL, 'd' },
   { "help", 0, NULL, 'h' },
+  { "foreground", 0, NULL, 'F' },
   { "version", 0, NULL,'V' },
 
   /* Key management options */
@@ -70,8 +71,9 @@ Usage: silcd [options]\n\
 \n\
   Generic Options:\n\
   -f  --config-file=FILE        Alternate configuration file\n\
-  -d  --debug=string            Enable debugging (no daemon)\n\
+  -d  --debug=string            Enable debugging (Implies --foreground)\n\
   -h  --help                    Display this message\n\
+  -F  --foreground              Dont fork\n\
   -V  --version                 Display version\n\
 \n\
   Key Management Options:\n\
@@ -99,6 +101,7 @@ int main(int argc, char **argv)
 {
   int ret;
   int opt, option_index;
+  int foreground = FALSE;
   char *config_file = NULL;
   SilcServer silcd;
   struct sigaction sa;
@@ -108,7 +111,7 @@ int main(int argc, char **argv)
 
   /* Parse command line arguments */
   if (argc > 1) {
-    while ((opt = getopt_long(argc, argv, "cf:d:hVC:",
+    while ((opt = getopt_long(argc, argv, "cf:d:hFVC:",
                              long_opts, &option_index)) != EOF) {
       switch(opt) 
        {
@@ -136,6 +139,9 @@ int main(int argc, char **argv)
        case 'f':
          config_file = strdup(optarg);
          break;
+       case 'F':
+         foreground = TRUE;
+         break;
 
          /*
           * Key management options
@@ -201,17 +207,23 @@ int main(int argc, char **argv)
   sigemptyset(&sa.sa_mask);
   sigaction(SIGPIPE, &sa, NULL);
 
-  if (silc_debug == FALSE)
-    /* Before running the server, fork to background and set
-       both user and group no non-root */    
+  if ((silc_debug == FALSE) && (foreground == FALSE))
+    /* Before running the server, fork to background. */    
     silc_server_daemonise(silcd);
 
   /* Set /var/run/silcd.pid */
   unlink(SILC_SERVER_PID_FILE);
   memset(pid, 0, sizeof(pid));
   snprintf(pid, sizeof(pid) - 1, "%d\n", getpid());
-  silc_file_writefile(SILC_SERVER_PID_FILE, pid, strlen(pid));
+  if (silcd->config->pidfile && silcd->config->pidfile->pid_file) {
+    silc_file_writefile(silcd->config->pidfile->pid_file, pid, strlen(pid));
+  } else {
+    silc_file_writefile(SILC_SERVER_PID_FILE, pid, strlen(pid));
+  }
   
+  /* Drop root. */
+  silc_server_drop(silcd);
+
   /* Run the server. When this returns the server has been stopped
      and we will exit. */
   silc_server_run(silcd);
index 29cfc2bbeecfacc17608466de8086cd54c8b5dba..f775d60c6fdbb82513df57edf38751e8b6298d4b 100644 (file)
@@ -838,6 +838,9 @@ SILC_CLIENT_CMD_REPLY_FUNC(info)
     /* Add it to the cache */
     silc_idcache_add(conn->server_cache, server->server_name,
                     server->server_id, (void *)server, FALSE);
+
+    if (SILC_ID_SERVER_COMPARE(server_id, conn->remote_id))
+      goto out;
   } else {
     server = (SilcServerEntry)id_cache->context;
   }
index 3c2dea539a1d6c1dc957f7d5487f689798d53423..f68c1b806c0d59c195865f5a4008ee4c9070d046 100644 (file)
 #include "silcincludes.h"
 
 #ifdef HAVE_GETSID
-extern __pid_t getsid (__pid_t __pid);
+extern pid_t getsid (pid_t __pid);
 #endif
 
 #ifdef HAVE_GETPGID
-extern __pid_t getpgid (__pid_t __pid);
+extern pid_t getpgid (pid_t __pid);
 #endif
 
 #undef SILC_RNG_DEBUG