diff options
Diffstat (limited to 'src/setup/gnunet-setup.c')
-rw-r--r-- | src/setup/gnunet-setup.c | 108 |
1 files changed, 104 insertions, 4 deletions
diff --git a/src/setup/gnunet-setup.c b/src/setup/gnunet-setup.c index f36ec7d4..d41be339 100644 --- a/src/setup/gnunet-setup.c +++ b/src/setup/gnunet-setup.c | |||
@@ -26,6 +26,9 @@ | |||
26 | #if ENABLE_NLS | 26 | #if ENABLE_NLS |
27 | #include <locale.h> | 27 | #include <locale.h> |
28 | #endif | 28 | #endif |
29 | #if HAVE_LIBGKSU_LIBGKSU_H | ||
30 | #include <libgksu/gksu.h> | ||
31 | #endif | ||
29 | #include "gnunet-setup.h" | 32 | #include "gnunet-setup.h" |
30 | #include "gnunet-setup-options.h" | 33 | #include "gnunet-setup-options.h" |
31 | #include "gnunet-setup-gns.h" | 34 | #include "gnunet-setup-gns.h" |
@@ -62,6 +65,20 @@ static struct GNUNET_OS_Process *resolver; | |||
62 | */ | 65 | */ |
63 | static struct GNUNET_OS_Process *namestore; | 66 | static struct GNUNET_OS_Process *namestore; |
64 | 67 | ||
68 | #if HAVE_LIBGKSU_LIBGKSU_H | ||
69 | /** | ||
70 | * Flag to emable privilege escalation. | ||
71 | */ | ||
72 | static int do_gksu; | ||
73 | #endif | ||
74 | |||
75 | /** | ||
76 | * Show all configuration options, even if we are run | ||
77 | * as a normal user and a 'gnunet' user exists and thus | ||
78 | * most options should not apply to the normal user. | ||
79 | */ | ||
80 | static int force_full_setup; | ||
81 | |||
65 | 82 | ||
66 | /** | 83 | /** |
67 | * Get an object from the main window. | 84 | * Get an object from the main window. |
@@ -424,6 +441,35 @@ start_namestore (void *cls, | |||
424 | } | 441 | } |
425 | 442 | ||
426 | 443 | ||
444 | #if HAVE_LIBGKSU_LIBGKSU_H | ||
445 | /** | ||
446 | * Try elevating user priviledges to run as user 'gnunet' or 'root'. | ||
447 | * | ||
448 | * @param username user gnunet-setup should be run as | ||
449 | * @return GNUNET_OK on success | ||
450 | */ | ||
451 | static int | ||
452 | try_gksu (const char *username) | ||
453 | { | ||
454 | GksuContext *gksu; | ||
455 | GError *err; | ||
456 | |||
457 | gksu = gksu_context_new (); | ||
458 | gksu_context_set_user (gksu, username); | ||
459 | gksu_context_set_command (gksu, "gnunet-setup"); | ||
460 | gksu_context_set_description (gksu, _("Elevate priviledges to setup GNUnet on the host")); | ||
461 | gksu_context_set_message (gksu, _("Enter password to run gnunet-setup as user 'gnunet'")); | ||
462 | if (gksu_run_full (gksu, | ||
463 | NULL, NULL, | ||
464 | NULL, NULL, | ||
465 | &err)) | ||
466 | return GNUNET_OK; | ||
467 | g_object_unref (err); | ||
468 | return GNUNET_SYSERR; | ||
469 | } | ||
470 | #endif | ||
471 | |||
472 | |||
427 | /** | 473 | /** |
428 | * Actual main method that sets up the configuration window. | 474 | * Actual main method that sets up the configuration window. |
429 | * | 475 | * |
@@ -434,17 +480,49 @@ static void | |||
434 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 480 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
435 | { | 481 | { |
436 | GtkWidget *main_window; | 482 | GtkWidget *main_window; |
483 | uid_t my_uid; | ||
484 | struct passwd *gnunet_pw; | ||
485 | |||
486 | my_uid = getuid (); | ||
487 | gnunet_pw = getpwnam ("gnunet"); | ||
488 | #if HAVE_LIBGKSU_LIBGKSU_H | ||
489 | |||
490 | if ( (0 != do_gksu) && | ||
491 | (0 != my_uid) && | ||
492 | (NULL != gnunet_pw) && | ||
493 | (my_uid != gnunet_pw->pw_uid) && | ||
494 | (GNUNET_OK == try_gksu ("gnunet"))) | ||
495 | { | ||
496 | GNUNET_GTK_main_loop_quit (cls); | ||
497 | return; | ||
498 | } | ||
499 | #endif | ||
437 | 500 | ||
438 | ml = cls; | 501 | ml = cls; |
439 | |||
440 | if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) | 502 | if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) |
441 | { | ||
442 | return; | 503 | return; |
443 | } | ||
444 | 504 | ||
445 | cfgName = GNUNET_GTK_main_loop_get_configuration_file (ml); | 505 | cfgName = GNUNET_GTK_main_loop_get_configuration_file (ml); |
446 | cfg = GNUNET_CONFIGURATION_create (); | 506 | cfg = GNUNET_CONFIGURATION_create (); |
447 | (void) GNUNET_CONFIGURATION_load (cfg, cfgName); | 507 | if ( (0 != my_uid) && |
508 | (NULL != gnunet_pw) && | ||
509 | (my_uid != gnunet_pw->pw_uid) && | ||
510 | (0 == force_full_setup) ) | ||
511 | { | ||
512 | /* load system defaults, system/'gnunet' user's configuration and THEN | ||
513 | our configuration file */ | ||
514 | if (GNUNET_YES == | ||
515 | GNUNET_DISK_file_test ("/etc/gnunet.conf")) | ||
516 | (void) GNUNET_CONFIGURATION_load (cfg, "/etc/gnunet.conf"); | ||
517 | else | ||
518 | (void) GNUNET_CONFIGURATION_load (cfg, "~gnunet/.gnunet/gnunet.conf"); | ||
519 | (void) GNUNET_CONFIGURATION_parse (cfg, cfgName); | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | /* only load system defaults and our configuration file */ | ||
524 | (void) GNUNET_CONFIGURATION_load (cfg, cfgName); | ||
525 | } | ||
448 | main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog")); | 526 | main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog")); |
449 | GNUNET_CLIENT_service_test ("resolver", | 527 | GNUNET_CLIENT_service_test ("resolver", |
450 | cfg, | 528 | cfg, |
@@ -456,6 +534,20 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
456 | &start_namestore, NULL); | 534 | &start_namestore, NULL); |
457 | load_options (); | 535 | load_options (); |
458 | GNUNET_SETUP_gns_init (); | 536 | GNUNET_SETUP_gns_init (); |
537 | if ( (0 != my_uid) && | ||
538 | (NULL != gnunet_pw) && | ||
539 | (my_uid != gnunet_pw->pw_uid) && | ||
540 | (0 == force_full_setup) ) | ||
541 | { | ||
542 | /* hide all options that are not for individual users; this | ||
543 | run is only for per-user options, not for per-peer options */ | ||
544 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_general_vbox"))); | ||
545 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_transport_main_frame"))); | ||
546 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_network_tab_vbox"))); | ||
547 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_fs_main_vbox"))); | ||
548 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_vpn_vbox"))); | ||
549 | gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_namestore_vbox"))); | ||
550 | } | ||
459 | gtk_widget_show (main_window); | 551 | gtk_widget_show (main_window); |
460 | gtk_window_present (GTK_WINDOW (main_window)); | 552 | gtk_window_present (GTK_WINDOW (main_window)); |
461 | } | 553 | } |
@@ -472,6 +564,14 @@ int | |||
472 | main (int argc, char *const *argv) | 564 | main (int argc, char *const *argv) |
473 | { | 565 | { |
474 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 566 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
567 | #if HAVE_LIBGKSU_LIBGKSU_H | ||
568 | { 'e', "elevate-priviledges", NULL, | ||
569 | gettext_noop ("run as user 'gnunet', if necessary by executing gksu to elevate rights"), | ||
570 | 0, &GNUNET_GETOPT_set_one, &do_gksu }, | ||
571 | #endif | ||
572 | { 'f', "force-full-setup", NULL, | ||
573 | gettext_noop ("force showing the full set of options, even if gnunet-setup is run as a normal user and as a user 'gnunet' exists on the system, most options should not apply to the normal user as GNUnet should be run by the 'gnunet' user"), | ||
574 | 0, &GNUNET_GETOPT_set_one, &force_full_setup }, | ||
475 | GNUNET_GETOPT_OPTION_END | 575 | GNUNET_GETOPT_OPTION_END |
476 | }; | 576 | }; |
477 | int ret; | 577 | int ret; |