[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24585 - in gnunet-gtk: . src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24585 - in gnunet-gtk: . src/setup |
Date: |
Mon, 29 Oct 2012 00:10:59 +0100 |
Author: grothoff
Date: 2012-10-29 00:10:59 +0100 (Mon, 29 Oct 2012)
New Revision: 24585
Modified:
gnunet-gtk/configure.ac
gnunet-gtk/src/setup/Makefile.am
gnunet-gtk/src/setup/gnunet-setup.c
Log:
adding gksu for priviledge escalation to run gnunet-setup as user gnunet ---
untested
Modified: gnunet-gtk/configure.ac
===================================================================
--- gnunet-gtk/configure.ac 2012-10-28 23:10:33 UTC (rev 24584)
+++ gnunet-gtk/configure.ac 2012-10-28 23:10:59 UTC (rev 24585)
@@ -176,7 +176,7 @@
AC_MSG_CHECKING(for libqrencode)
AC_ARG_WITH(qrencode,
[ --with-qrencode=PFX Base of libqrencode installation],
- [AC_MSG_RESULT([$with_extractor])
+ [AC_MSG_RESULT([$with_qrencode])
case $with_qrencode in
no)
;;
@@ -203,6 +203,7 @@
AC_SUBST(QR_CFLAGS)
AC_SUBST(QR_LIBS)
+
AC_MSG_CHECKING(for gtk)
check_for_3=3.0.0
check_for_2=false
@@ -248,6 +249,7 @@
fi
fi
+
AM_CONDITIONAL(HAVE_GTK, test x$without_gtk != xtrue)
if test $without_gtk != true
then
@@ -261,7 +263,40 @@
AC_CHECK_HEADERS([glib.h gmodule.h gtk/gtk.h
gdk/gdk.h],,AC_MSG_ERROR([gnunet-gtk requires GTK]))
+# test for libgksu
+gksu=0
+GKSU_LIBS="-lgksu"
+AC_MSG_CHECKING(for libgksu)
+AC_ARG_WITH(gksu,
+ [ --with-gksu=PFX Base of libgksu installation],
+ [AC_MSG_RESULT([$with_gksu])
+ case $with_gksu in
+ no)
+ ;;
+ yes)
+ AC_CHECK_HEADERS(libgksu/libgksu.h,gksu=1)
+ ;;
+ *)
+ CPPFLAGS="-I$with_gksu/include $CPPFLAGS"
+ GKSU_CFLAGS="-I$with_gksu/include"
+ GKSU_LIBS="-L$with_gksu/lib -lgksu"
+ AC_CHECK_HEADERS(libgksu/libgksu.h,gksu=1)
+ ;;
+ esac
+ ],
+ [AC_MSG_RESULT([--with-gksu not specified])
+ AC_CHECK_HEADERS(libgksu/libgksu.h,gksu=1)])
+if test "$gksu" != 1
+then
+GKSU_LIBS=""
+GKSU_CFLAGS=""
+fi
+
+AC_SUBST(GKSU_CFLAGS)
+AC_SUBST(GKSU_LIBS)
+
+
# test for Glade
glade=0
lookin=${prefix}
@@ -517,3 +552,8 @@
then
AC_MSG_WARN([gnunet-setup will not include QR support])
fi
+
+if test "$gksu" != 1
+then
+ AC_MSG_WARN([gnunet-setup will not include GKSU support])
+fi
Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am 2012-10-28 23:10:33 UTC (rev 24584)
+++ gnunet-gtk/src/setup/Makefile.am 2012-10-28 23:10:59 UTC (rev 24585)
@@ -2,10 +2,7 @@
INCLUDES = \
-I$(top_srcdir)/ \
- -I$(top_srcdir)/src/include \
- @GTK_CFLAGS@ \
- @GNUNET_CFLAGS@ \
- @GLADE_CFLAGS@
+ -I$(top_srcdir)/src/include
if MINGW
WINLIBS = -lregex
@@ -34,9 +31,16 @@
gnunet-setup-hostlist-server.c
gnunet_setup_LDADD = \
$(top_builddir)/src/lib/libgnunetgtk.la \
- @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ @QR_CFLAGS@ @QR_LIBS@ \
+ @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ @QR_LIBS@ @GKSU_LIBS@ \
$(WINLIBS) \
-lgnunetutil -lgnunetnat -lgnunetnamestore \
$(INTLLIBS)
+gnunet_setup_CFLAGS = \
+ @GTK_CFLAGS@ \
+ @GNUNET_CFLAGS@ \
+ @GLADE_CFLAGS@ \
+ @QR_CFLAGS@ \
+ @GKSU_CFLAGS@
+
gnunet_setup_LDFLAGS = \
-export-dynamic
Modified: gnunet-gtk/src/setup/gnunet-setup.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup.c 2012-10-28 23:10:33 UTC (rev 24584)
+++ gnunet-gtk/src/setup/gnunet-setup.c 2012-10-28 23:10:59 UTC (rev 24585)
@@ -26,6 +26,9 @@
#if ENABLE_NLS
#include <locale.h>
#endif
+#if HAVE_LIBGKSU_LIBGKSU_H
+#include <libgksu/gksu.h>
+#endif
#include "gnunet-setup.h"
#include "gnunet-setup-options.h"
#include "gnunet-setup-gns.h"
@@ -62,8 +65,22 @@
*/
static struct GNUNET_OS_Process *namestore;
+#if HAVE_LIBGKSU_LIBGKSU_H
+/**
+ * Flag to emable privilege escalation.
+ */
+static int do_gksu;
+#endif
/**
+ * Show all configuration options, even if we are run
+ * as a normal user and a 'gnunet' user exists and thus
+ * most options should not apply to the normal user.
+ */
+static int force_full_setup;
+
+
+/**
* Get an object from the main window.
*
* @param name name of the object
@@ -424,7 +441,36 @@
}
+#if HAVE_LIBGKSU_LIBGKSU_H
/**
+ * Try elevating user priviledges to run as user 'gnunet' or 'root'.
+ *
+ * @param username user gnunet-setup should be run as
+ * @return GNUNET_OK on success
+ */
+static int
+try_gksu (const char *username)
+{
+ GksuContext *gksu;
+ GError *err;
+
+ gksu = gksu_context_new ();
+ gksu_context_set_user (gksu, username);
+ gksu_context_set_command (gksu, "gnunet-setup");
+ gksu_context_set_description (gksu, _("Elevate priviledges to setup GNUnet
on the host"));
+ gksu_context_set_message (gksu, _("Enter password to run gnunet-setup as
user 'gnunet'"));
+ if (gksu_run_full (gksu,
+ NULL, NULL,
+ NULL, NULL,
+ &err))
+ return GNUNET_OK;
+ g_object_unref (err);
+ return GNUNET_SYSERR;
+}
+#endif
+
+
+/**
* Actual main method that sets up the configuration window.
*
* @param cls the main loop handle
@@ -434,17 +480,49 @@
run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GtkWidget *main_window;
+ uid_t my_uid;
+ struct passwd *gnunet_pw;
- ml = cls;
+ my_uid = getuid ();
+ gnunet_pw = getpwnam ("gnunet");
+#if HAVE_LIBGKSU_LIBGKSU_H
- if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
+ if ( (0 != do_gksu) &&
+ (0 != my_uid) &&
+ (NULL != gnunet_pw) &&
+ (my_uid != gnunet_pw->pw_uid) &&
+ (GNUNET_OK == try_gksu ("gnunet")))
{
+ GNUNET_GTK_main_loop_quit (cls);
return;
}
+#endif
+ ml = cls;
+ if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
+ return;
+
cfgName = GNUNET_GTK_main_loop_get_configuration_file (ml);
cfg = GNUNET_CONFIGURATION_create ();
- (void) GNUNET_CONFIGURATION_load (cfg, cfgName);
+ if ( (0 != my_uid) &&
+ (NULL != gnunet_pw) &&
+ (my_uid != gnunet_pw->pw_uid) &&
+ (0 == force_full_setup) )
+ {
+ /* load system defaults, system/'gnunet' user's configuration and THEN
+ our configuration file */
+ if (GNUNET_YES ==
+ GNUNET_DISK_file_test ("/etc/gnunet.conf"))
+ (void) GNUNET_CONFIGURATION_load (cfg, "/etc/gnunet.conf");
+ else
+ (void) GNUNET_CONFIGURATION_load (cfg, "~gnunet/.gnunet/gnunet.conf");
+ (void) GNUNET_CONFIGURATION_parse (cfg, cfgName);
+ }
+ else
+ {
+ /* only load system defaults and our configuration file */
+ (void) GNUNET_CONFIGURATION_load (cfg, cfgName);
+ }
main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog"));
GNUNET_CLIENT_service_test ("resolver",
cfg,
@@ -456,6 +534,20 @@
&start_namestore, NULL);
load_options ();
GNUNET_SETUP_gns_init ();
+ if ( (0 != my_uid) &&
+ (NULL != gnunet_pw) &&
+ (my_uid != gnunet_pw->pw_uid) &&
+ (0 == force_full_setup) )
+ {
+ /* hide all options that are not for individual users; this
+ run is only for per-user options, not for per-peer options */
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_general_vbox")));
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_transport_main_frame")));
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_network_tab_vbox")));
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_fs_main_vbox")));
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_vpn_vbox")));
+ gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_namestore_vbox")));
+ }
gtk_widget_show (main_window);
gtk_window_present (GTK_WINDOW (main_window));
}
@@ -472,6 +564,14 @@
main (int argc, char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+#if HAVE_LIBGKSU_LIBGKSU_H
+ { 'e', "elevate-priviledges", NULL,
+ gettext_noop ("run as user 'gnunet', if necessary by executing gksu to
elevate rights"),
+ 0, &GNUNET_GETOPT_set_one, &do_gksu },
+#endif
+ { 'f', "force-full-setup", NULL,
+ 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"),
+ 0, &GNUNET_GETOPT_set_one, &force_full_setup },
GNUNET_GETOPT_OPTION_END
};
int ret;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24585 - in gnunet-gtk: . src/setup,
gnunet <=