gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6017 - gnunet-gtk/src/plugins/daemon


From: gnunet
Subject: [GNUnet-SVN] r6017 - gnunet-gtk/src/plugins/daemon
Date: Sat, 22 Dec 2007 13:19:30 -0700 (MST)

Author: moon
Date: 2007-12-22 13:19:30 -0700 (Sat, 22 Dec 2007)
New Revision: 6017

Modified:
   gnunet-gtk/src/plugins/daemon/daemon.c
Log:
libgksu2 support for starting gnunetd

Modified: gnunet-gtk/src/plugins/daemon/daemon.c
===================================================================
--- gnunet-gtk/src/plugins/daemon/daemon.c      2007-12-22 19:18:01 UTC (rev 
6016)
+++ gnunet-gtk/src/plugins/daemon/daemon.c      2007-12-22 20:19:30 UTC (rev 
6017)
@@ -31,7 +31,17 @@
 #include <GNUnet/gnunet_stats_lib.h>
 #include <GNUnet/gnunet_util.h>
 #include <gtk/gtk.h>
+#include <glib/gerror.h>
 
+#ifdef WITH_LIBGKSU2
+/* Not used because libgksu2 headers have broken depends in Debian
+And this is not really needed
+#include <libgksu/libgksu.h> */
+gboolean
+gksu_run (gchar *command_line,
+          GError **error);
+#endif
+
 static struct GNUNET_CronManager *cron;
 
 static struct GNUNET_GE_Context *ectx;
@@ -129,7 +139,6 @@
   struct GNUNET_GC_Configuration *dcfg;
   char *fn;
   char *user;
-  struct passwd *pws;
 
   if (once)
     {
@@ -153,7 +162,7 @@
                               "gnunetdconfigFileChooserButton");
       GNUNET_GC_get_configuration_value_string (cfg, "NETWORK", "HOST",
                                                 "localhost", &host);
-      if (strcmp (host, "localhost") == 0)
+      if (strncmp (host, "localhost:", 10) == 0)
         isLocal = TRUE;
       else
         isLocal = FALSE;
@@ -163,9 +172,13 @@
   if (ret == 0)
     {
       canStart = 0;
-      if ((isLocal) &&
-          (NULL !=
-           (fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)))))
+         fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
+         if (NULL == fn)
+           GNUNET_GC_get_configuration_value_filename (cfg, "DAEMON",
+                                                                               
                    "CONFIGFILE",
+                                                                               
                    GNUNET_DEFAULT_DAEMON_CONFIG_FILE,
+                                                                               
                    &fn);
+      if (isLocal && fn)
         {
           if (GNUNET_disk_file_test (ectx, fn) == GNUNET_YES)
             {
@@ -179,7 +192,10 @@
                                                         "USER", "", &user);
               if (strlen (user) > 0)
                 {
-#ifndef WINDOWS
+#if defined(WINDOWS) || defined(WITH_LIBGKSU2)
+                  canStart = 1;
+#else
+                                 struct passwd *pws;
                   if (NULL == (pws = getpwnam (user)))
                     {
                       canStart = 0;
@@ -190,9 +206,7 @@
                         canStart = (geteuid () == 0);
                       else
                         canStart = 1;
-                    }                 
-#else
-                  canStart = 1;
+                    }
 #endif
                 }
               GNUNET_free (user);
@@ -289,6 +303,9 @@
   GtkWidget *launchEntry;
   GtkWidget *chooser;
   char *fn;
+  char *user;
+  struct GNUNET_GC_Configuration *dcfg;
+  int code = 0;
 
   launchEntry =
     glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "startDaemon");
@@ -306,7 +323,47 @@
                                 "gnunetdconfigFileChooserButton");
       fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
       GNUNET_GE_BREAK (ectx, fn != NULL);
-      if (GNUNET_SYSERR != GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES))
+
+      dcfg = GNUNET_GC_create ();
+      if (0 != GNUNET_GC_parse_configuration (dcfg, fn))
+        user = NULL;
+      GNUNET_GC_get_configuration_value_string (dcfg,
+                                                "GNUNETD",
+                                                "USER", "", &user);
+#ifdef WITH_LIBGKSU2
+         char *command;
+         GError *gerror = NULL;
+         struct passwd *pws;
+         if (strlen (user) > 0)
+           {
+          pws = getpwnam (user);
+          if (pws->pw_uid != getuid ())
+                       {
+              command = g_strconcat ("gnunetd -c ", fn, NULL);
+                         code = gksu_run (command, &gerror);
+                         GNUNET_free (command);
+                         if (gerror)
+                {
+                                 GNUNET_GTK_add_log_entry (_("Launching 
gnunetd failed\n"));
+
+                                 g_error_free (gerror);
+                }
+              else
+                {
+                  GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
+                }
+             g_free (fn);
+                        cronCheckDaemon (NULL);
+                        return;
+                       }
+           else
+             code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES); 
+               }
+#else
+     code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES);
+#endif
+                                               
+        if (GNUNET_SYSERR != code)
         {
           GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
         }
@@ -315,7 +372,8 @@
           GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n"));
         }
       if (fn != NULL)
-        g_free (fn);
+      g_free (fn);
+         cronCheckDaemon (NULL);
     }
 }
 
@@ -434,7 +492,7 @@
 #endif
   GNUNET_free (daemon_config);
 
- cron = GNUNET_GTK_get_cron_manager ();
+  cron = GNUNET_GTK_get_cron_manager ();
   GNUNET_cron_add_job (cron, &cronCheckDaemon, 0, 15 * GNUNET_CRON_SECONDS,
                        NULL);
   GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES,
@@ -494,7 +552,7 @@
 }
 
 /**
-* Update sensitivity of daemon configuration buttons
+* Update sensitivity of daemon buttons
 */
 void
 on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton,
@@ -504,6 +562,7 @@
   GtkWidget *startDaemonConfWizard;
   GtkWidget *startDaemonConfTool;
   char *conffile;
+  int ret;
 
   startDaemonConfWizard
         = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
@@ -522,6 +581,8 @@
       gtk_widget_set_sensitive (startDaemonConfWizard, FALSE);
       gtk_widget_set_sensitive (startDaemonConfTool, FALSE);
     }
+  ret = 0;
+  GNUNET_GTK_save_call (&doUpdateMenus, &ret);
   GNUNET_free_non_null (conffile);
 #endif
   return;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]