aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoon <moon@140774ce-b5e7-0310-ab8b-a85725594a96>2007-12-22 20:19:30 +0000
committerMoon <moon@140774ce-b5e7-0310-ab8b-a85725594a96>2007-12-22 20:19:30 +0000
commit320d74c8aea920047f1752714bab970acdd0170d (patch)
tree005e2d92415f72da53223048981f746c7b9ef402
parent5e63be9f5f6263f38c141e5242c92950d60477be (diff)
downloadgnunet-gtk-320d74c8aea920047f1752714bab970acdd0170d.tar.gz
gnunet-gtk-320d74c8aea920047f1752714bab970acdd0170d.zip
libgksu2 support for starting gnunetd
-rw-r--r--src/plugins/daemon/daemon.c87
1 files 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 @@
31#include <GNUnet/gnunet_stats_lib.h> 31#include <GNUnet/gnunet_stats_lib.h>
32#include <GNUnet/gnunet_util.h> 32#include <GNUnet/gnunet_util.h>
33#include <gtk/gtk.h> 33#include <gtk/gtk.h>
34#include <glib/gerror.h>
35
36#ifdef WITH_LIBGKSU2
37/* Not used because libgksu2 headers have broken depends in Debian
38And this is not really needed
39#include <libgksu/libgksu.h> */
40gboolean
41gksu_run (gchar *command_line,
42 GError **error);
43#endif
34 44
35static struct GNUNET_CronManager *cron; 45static struct GNUNET_CronManager *cron;
36 46
@@ -129,7 +139,6 @@ doUpdateMenus (void *arg)
129 struct GNUNET_GC_Configuration *dcfg; 139 struct GNUNET_GC_Configuration *dcfg;
130 char *fn; 140 char *fn;
131 char *user; 141 char *user;
132 struct passwd *pws;
133 142
134 if (once) 143 if (once)
135 { 144 {
@@ -153,7 +162,7 @@ doUpdateMenus (void *arg)
153 "gnunetdconfigFileChooserButton"); 162 "gnunetdconfigFileChooserButton");
154 GNUNET_GC_get_configuration_value_string (cfg, "NETWORK", "HOST", 163 GNUNET_GC_get_configuration_value_string (cfg, "NETWORK", "HOST",
155 "localhost", &host); 164 "localhost", &host);
156 if (strcmp (host, "localhost") == 0) 165 if (strncmp (host, "localhost:", 10) == 0)
157 isLocal = TRUE; 166 isLocal = TRUE;
158 else 167 else
159 isLocal = FALSE; 168 isLocal = FALSE;
@@ -163,9 +172,13 @@ doUpdateMenus (void *arg)
163 if (ret == 0) 172 if (ret == 0)
164 { 173 {
165 canStart = 0; 174 canStart = 0;
166 if ((isLocal) && 175 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
167 (NULL != 176 if (NULL == fn)
168 (fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser))))) 177 GNUNET_GC_get_configuration_value_filename (cfg, "DAEMON",
178 "CONFIGFILE",
179 GNUNET_DEFAULT_DAEMON_CONFIG_FILE,
180 &fn);
181 if (isLocal && fn)
169 { 182 {
170 if (GNUNET_disk_file_test (ectx, fn) == GNUNET_YES) 183 if (GNUNET_disk_file_test (ectx, fn) == GNUNET_YES)
171 { 184 {
@@ -179,7 +192,10 @@ doUpdateMenus (void *arg)
179 "USER", "", &user); 192 "USER", "", &user);
180 if (strlen (user) > 0) 193 if (strlen (user) > 0)
181 { 194 {
182#ifndef WINDOWS 195#if defined(WINDOWS) || defined(WITH_LIBGKSU2)
196 canStart = 1;
197#else
198 struct passwd *pws;
183 if (NULL == (pws = getpwnam (user))) 199 if (NULL == (pws = getpwnam (user)))
184 { 200 {
185 canStart = 0; 201 canStart = 0;
@@ -190,9 +206,7 @@ doUpdateMenus (void *arg)
190 canStart = (geteuid () == 0); 206 canStart = (geteuid () == 0);
191 else 207 else
192 canStart = 1; 208 canStart = 1;
193 } 209 }
194#else
195 canStart = 1;
196#endif 210#endif
197 } 211 }
198 GNUNET_free (user); 212 GNUNET_free (user);
@@ -289,6 +303,9 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
289 GtkWidget *launchEntry; 303 GtkWidget *launchEntry;
290 GtkWidget *chooser; 304 GtkWidget *chooser;
291 char *fn; 305 char *fn;
306 char *user;
307 struct GNUNET_GC_Configuration *dcfg;
308 int code = 0;
292 309
293 launchEntry = 310 launchEntry =
294 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "startDaemon"); 311 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "startDaemon");
@@ -306,7 +323,47 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
306 "gnunetdconfigFileChooserButton"); 323 "gnunetdconfigFileChooserButton");
307 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); 324 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
308 GNUNET_GE_BREAK (ectx, fn != NULL); 325 GNUNET_GE_BREAK (ectx, fn != NULL);
309 if (GNUNET_SYSERR != GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES)) 326
327 dcfg = GNUNET_GC_create ();
328 if (0 != GNUNET_GC_parse_configuration (dcfg, fn))
329 user = NULL;
330 GNUNET_GC_get_configuration_value_string (dcfg,
331 "GNUNETD",
332 "USER", "", &user);
333#ifdef WITH_LIBGKSU2
334 char *command;
335 GError *gerror = NULL;
336 struct passwd *pws;
337 if (strlen (user) > 0)
338 {
339 pws = getpwnam (user);
340 if (pws->pw_uid != getuid ())
341 {
342 command = g_strconcat ("gnunetd -c ", fn, NULL);
343 code = gksu_run (command, &gerror);
344 GNUNET_free (command);
345 if (gerror)
346 {
347 GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n"));
348
349 g_error_free (gerror);
350 }
351 else
352 {
353 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
354 }
355 g_free (fn);
356 cronCheckDaemon (NULL);
357 return;
358 }
359 else
360 code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES);
361 }
362#else
363 code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES);
364#endif
365
366 if (GNUNET_SYSERR != code)
310 { 367 {
311 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n")); 368 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
312 } 369 }
@@ -315,7 +372,8 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
315 GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n")); 372 GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n"));
316 } 373 }
317 if (fn != NULL) 374 if (fn != NULL)
318 g_free (fn); 375 g_free (fn);
376 cronCheckDaemon (NULL);
319 } 377 }
320} 378}
321 379
@@ -434,7 +492,7 @@ init_daemon (struct GNUNET_GE_Context *e, struct GNUNET_GC_Configuration *c)
434#endif 492#endif
435 GNUNET_free (daemon_config); 493 GNUNET_free (daemon_config);
436 494
437 cron = GNUNET_GTK_get_cron_manager (); 495 cron = GNUNET_GTK_get_cron_manager ();
438 GNUNET_cron_add_job (cron, &cronCheckDaemon, 0, 15 * GNUNET_CRON_SECONDS, 496 GNUNET_cron_add_job (cron, &cronCheckDaemon, 0, 15 * GNUNET_CRON_SECONDS,
439 NULL); 497 NULL);
440 GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES, 498 GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES,
@@ -494,7 +552,7 @@ on_startDaemonConfTool_clicked_daemon (GtkWidget *widget, gpointer data)
494} 552}
495 553
496/** 554/**
497* Update sensitivity of daemon configuration buttons 555* Update sensitivity of daemon buttons
498*/ 556*/
499void 557void
500on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton, 558on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton,
@@ -504,6 +562,7 @@ on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton,
504 GtkWidget *startDaemonConfWizard; 562 GtkWidget *startDaemonConfWizard;
505 GtkWidget *startDaemonConfTool; 563 GtkWidget *startDaemonConfTool;
506 char *conffile; 564 char *conffile;
565 int ret;
507 566
508 startDaemonConfWizard 567 startDaemonConfWizard
509 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 568 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
@@ -522,6 +581,8 @@ on_gnunetdconfigfile_set_daemon (GtkWidget *filechooserbutton,
522 gtk_widget_set_sensitive (startDaemonConfWizard, FALSE); 581 gtk_widget_set_sensitive (startDaemonConfWizard, FALSE);
523 gtk_widget_set_sensitive (startDaemonConfTool, FALSE); 582 gtk_widget_set_sensitive (startDaemonConfTool, FALSE);
524 } 583 }
584 ret = 0;
585 GNUNET_GTK_save_call (&doUpdateMenus, &ret);
525 GNUNET_free_non_null (conffile); 586 GNUNET_free_non_null (conffile);
526#endif 587#endif
527 return; 588 return;