From 320d74c8aea920047f1752714bab970acdd0170d Mon Sep 17 00:00:00 2001 From: Moon Date: Sat, 22 Dec 2007 20:19:30 +0000 Subject: libgksu2 support for starting gnunetd --- src/plugins/daemon/daemon.c | 87 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c index 178a4732..69aee54a 100644 --- a/src/plugins/daemon/daemon.c +++ b/src/plugins/daemon/daemon.c @@ -31,6 +31,16 @@ #include #include #include +#include + +#ifdef WITH_LIBGKSU2 +/* Not used because libgksu2 headers have broken depends in Debian +And this is not really needed +#include */ +gboolean +gksu_run (gchar *command_line, + GError **error); +#endif static struct GNUNET_CronManager *cron; @@ -129,7 +139,6 @@ doUpdateMenus (void *arg) struct GNUNET_GC_Configuration *dcfg; char *fn; char *user; - struct passwd *pws; if (once) { @@ -153,7 +162,7 @@ doUpdateMenus (void *arg) "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 @@ doUpdateMenus (void *arg) 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 @@ doUpdateMenus (void *arg) "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 @@ doUpdateMenus (void *arg) canStart = (geteuid () == 0); else canStart = 1; - } -#else - canStart = 1; + } #endif } GNUNET_free (user); @@ -289,6 +303,9 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data) 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 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data) "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 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data) GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n")); } if (fn != NULL) - g_free (fn); + g_free (fn); + cronCheckDaemon (NULL); } } @@ -434,7 +492,7 @@ init_daemon (struct GNUNET_GE_Context *e, struct GNUNET_GC_Configuration *c) #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 @@ on_startDaemonConfTool_clicked_daemon (GtkWidget *widget, gpointer data) } /** -* Update sensitivity of daemon configuration buttons +* Update sensitivity of daemon buttons */ void on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton, @@ -504,6 +562,7 @@ on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton, GtkWidget *startDaemonConfWizard; GtkWidget *startDaemonConfTool; char *conffile; + int ret; startDaemonConfWizard = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), @@ -522,6 +581,8 @@ on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton, 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; -- cgit v1.2.3