1c86b90
--- gnome-system-monitor-2.9.90/configure.in.libgnomesu	2005-01-24 09:06:57.000000000 -0500
1c86b90
+++ gnome-system-monitor-2.9.90/configure.in	2005-02-02 15:03:45.000000000 -0500
1c86b90
@@ -19,9 +19,8 @@
1c86b90
 LIBGTOP_REQUIRED=2.9.5
1c86b90
 GTK_REQUIRED=2.5.0
1c86b90
 GNOME_VFS_REQUIRED=2.6.0
1c86b90
-LIBGNOMESU_REQUIRED=0.9.3
1c86b90
 
1c86b90
-PKG_CHECK_MODULES(PROCMAN, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgtop-2.0 >= $LIBGTOP_REQUIRED libwnck-1.0 >= $LIBWNCK_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED libgnomesu-1.0 >= $LIBGNOMESU_REQUIRED)
1c86b90
+PKG_CHECK_MODULES(PROCMAN, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgtop-2.0 >= $LIBGTOP_REQUIRED libwnck-1.0 >= $LIBWNCK_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED)
1c86b90
 
1c86b90
 
1c86b90
 AC_ARG_ENABLE(more-warnings,
1c86b90
--- gnome-system-monitor-2.9.90/src/procdialogs.c.libgnomesu	2005-01-13 19:05:00.000000000 -0500
1c86b90
+++ gnome-system-monitor-2.9.90/src/procdialogs.c	2005-02-02 15:03:45.000000000 -0500
1c86b90
@@ -23,7 +23,6 @@
1c86b90
 
1c86b90
 #include <signal.h>
1c86b90
 #include <string.h>
1c86b90
-#include <libgnomesu/libgnomesu.h>
1c86b90
 #include "procdialogs.h"
1c86b90
 #include "favorites.h"
1c86b90
 #include "proctable.h"
1c86b90
@@ -815,13 +814,101 @@
1c86b90
 void procdialog_create_root_password_dialog (gint type, ProcData *procdata, gint pid, 
1c86b90
 					     gint extra_value, gchar *text)
1c86b90
 {
1c86b90
+	GtkWidget *dialog;
1c86b90
+	GtkWidget *error_dialog;
1c86b90
+	GtkWidget *main_vbox;
1c86b90
+	GtkWidget *hbox;
1c86b90
+	GtkWidget *entry;
1c86b90
+	GtkWidget *label;
1c86b90
+	gchar *title = NULL, *button_label;
1c86b90
 	gchar *command;
1c86b90
+	gchar *password, *blank;
1c86b90
+	gint retval;
1c86b90
+
1c86b90
+	if (type == 0) {
1c86b90
+		if (extra_value == SIGKILL) {
1c86b90
+			title = g_strdup (_("Kill Process"));
1c86b90
+			button_label = g_strdup (_("_Kill Process"));
1c86b90
+		}
1c86b90
+		else {
1c86b90
+			title = g_strdup (_("End Process"));
1c86b90
+			button_label = g_strdup (_("_End Process"));
1c86b90
+		}
1c86b90
+	}
1c86b90
+	else {
1c86b90
+		title = g_strdup (_("Change Priority"));
1c86b90
+		button_label = g_strdup (_("Change _Priority"));
1c86b90
+	}
1c86b90
+		
1c86b90
+	dialog = gtk_dialog_new_with_buttons (title, NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
1c86b90
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1c86b90
+					      button_label, 100,
1c86b90
+					      NULL);
1c86b90
+	
1c86b90
+	main_vbox = GTK_DIALOG (dialog)->vbox;
1c86b90
+	
1c86b90
+	label = gtk_label_new (_(text));
1c86b90
+	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1c86b90
+	gtk_misc_set_padding (GTK_MISC (label), GNOME_PAD, 2 * GNOME_PAD);
1c86b90
+	gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
1c86b90
+	
1c86b90
+	hbox = gtk_hbox_new (FALSE, 0);
1c86b90
+	gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL);
1c86b90
+	gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
1c86b90
+	
1c86b90
+	label = gtk_label_new (_("Root Password :"));
1c86b90
+	gtk_misc_set_padding (GTK_MISC (label), GNOME_PAD_SMALL, 0);
1c86b90
+	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0);
1c86b90
+	
1c86b90
+	entry = gtk_entry_new ();
1c86b90
+	gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
1c86b90
+	gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, FALSE, 0);
1c86b90
+	g_signal_connect (G_OBJECT (entry), "activate",
1c86b90
+			  G_CALLBACK (entry_activate_cb), dialog);
1c86b90
+		
1c86b90
+	gtk_widget_show_all (main_vbox);
1c86b90
+	
1c86b90
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
1c86b90
+	gtk_widget_grab_focus (entry);
1c86b90
+		
1c86b90
+	g_free (title);	
1c86b90
+	g_free (button_label);
1c86b90
+	
1c86b90
+	retval = gtk_dialog_run (GTK_DIALOG (dialog));
1c86b90
+	gtk_widget_hide (dialog);
1c86b90
+	
1c86b90
+	if (retval == 100) {
1c86b90
+		password = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
1c86b90
+		
1c86b90
+		if (!password)
1c86b90
+			password = "";
1c86b90
+		blank = g_strdup (password);
1c86b90
+		if (strlen (blank))
1c86b90
+			memset (blank, ' ', strlen (blank));
1c86b90
+			
1c86b90
+		gtk_entry_set_text (GTK_ENTRY (entry), blank);
1c86b90
+		gtk_entry_set_text (GTK_ENTRY (entry), "");
1c86b90
+		g_free (blank);
1c86b90
+		
1c86b90
+		if (type == 0)
1c86b90
+			command = g_strdup_printf ("kill -s %d %d", extra_value, pid);
1c86b90
+		else
1c86b90
+			command = g_strdup_printf ("renice %d %d", extra_value, pid);
1c86b90
+			
1c86b90
+		if (su_run_with_password (command, password) == -1) {
1c86b90
+			error_dialog = gtk_message_dialog_new (NULL,
1c86b90
+							       GTK_DIALOG_DESTROY_WITH_PARENT,
1c86b90
+                                  			       GTK_MESSAGE_ERROR,
1c86b90
+                                  			       GTK_BUTTONS_OK,
1c86b90
+                                  			       "%s",
1c86b90
+                                  			      _("Wrong Password.")); 
1c86b90
+			gtk_dialog_run (GTK_DIALOG (error_dialog));
1c86b90
+			gtk_widget_destroy (error_dialog);
1c86b90
+		}
1c86b90
+		g_free (command);
1c86b90
+		
1c86b90
+	}
1c86b90
+	gtk_widget_destroy (dialog);
1c86b90
 
1c86b90
-	if (type == 0)
1c86b90
-		command = g_strdup_printf ("kill -s %d %d", extra_value, pid);
1c86b90
-	else
1c86b90
-		command = g_strdup_printf ("renice %d %d", extra_value, pid);
1c86b90
-	gnomesu_exec (command);
1c86b90
-	g_free (command);
1c86b90
 }
1c86b90
 
1c86b90
--- gnome-system-monitor-2.9.90/src/util.c.libgnomesu	2005-01-08 17:43:35.000000000 -0500
1c86b90
+++ gnome-system-monitor-2.9.90/src/util.c	2005-02-02 15:08:57.000000000 -0500
1c86b90
@@ -1,10 +1,294 @@
7776207
-#include "util.h"
7776207
 
7776207
+#define _GNU_SOURCE
7776207
 #include <config.h>
7776207
 
7776207
+#include <stdio.h>
7776207
+#include <stdlib.h>
7776207
+#include <string.h>
7776207
+#include <unistd.h>
7776207
+#include <fcntl.h>
7776207
+#include <signal.h>
7776207
+#include <pwd.h>
7776207
+#include <sys/types.h>
7776207
+#include <sys/ioctl.h>
7776207
+#include <sys/wait.h>
7776207
+
7776207
+
7776207
+#ifdef __FreeBSD__
7776207
+# include <errno.h>
7776207
+# include <libutil.h>
7776207
+#endif
7776207
+
7776207
+#ifdef __sun
7776207
+# include <errno.h>
7776207
+# include <unistd.h>
7776207
+# include <stropts.h>
7776207
+# include <sys/stream.h>
7776207
+# include <sys/termios.h>
7776207
+# include <sys/ptem.h>
7776207
+#endif
7776207
+
7776207
+#include "util.h"
7776207
+
1c86b90
 #include <gnome.h>
1c86b90
-#include <stddef.h>
1c86b90
 
7776207
+/* ABORT() kills GTK if we're not root, else it just exits.
7776207
+ */
7776207
+#define ABORT(root)			\
7776207
+		if (root == 0)		\
7776207
+			GTK_ABORT();	\
7776207
+		else			\
7776207
+			_exit(-1)
7776207
+
7776207
+/* GTK_ABORT() is supposed to kill GTK and exit.
7776207
+ */
7776207
+#define GTK_ABORT() do {			\
7776207
+			gtk_main_quit();	\
7776207
+			_exit(0);		\
7776207
+		    } while (0)
7776207
+
7776207
+/* OPEN_TTY() is supposed to return a file descriptor to a pseudo-terminal.
7776207
+ */
7776207
+#define OPEN_TTY() getpt()
7776207
+
7776207
+#ifdef __FreeBSD__
7776207
+/* FreeBSD doesn't have getpt(). This function emulates it's behaviour. */
7776207
+int getpt (void);
7776207
+
7776207
+int
7776207
+getpt ()
7776207
+{
7776207
+	int master, slave;
7776207
+
7776207
+	if (openpty (&master, &slave, NULL, NULL, NULL) < 0) {
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	return master;
7776207
+}
7776207
+#endif
7776207
+
7776207
+#ifdef __sun
7776207
+/* Sun doesn't have getpt().  This function emulates it's behavior. */
7776207
+int getpt (void);
7776207
+
7776207
+int
7776207
+getpt ()
7776207
+{
7776207
+	int fdm, fds;
7776207
+	extern int errno;
7776207
+	char *slavename;
7776207
+	/* extern char *ptsname(); */
7776207
+
7776207
+	/* open master */
7776207
+	fdm = open("/dev/ptmx", O_RDWR);
7776207
+	if ( fdm < 0 ) {
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	if ( grantpt(fdm) < 0 )	{	/* change permission ofslave */
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	if ( unlockpt(fdm) < 0 ) {	/* unlock slave */
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	slavename = ptsname(fdm);	/* get name of slave */
7776207
+	if ( slavename == NULL ) {
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	fds = open(slavename, O_RDWR);        /* open slave */
7776207
+	if ( fds < 0 ) {
7776207
+		/* Simulate getpt()'s only error condition. */
7776207
+		errno = ENOENT;
7776207
+		return -1;
7776207
+	}
7776207
+	ioctl(fds, I_PUSH, "ptem");           /* push ptem * /
7776207
+	ioctl(fds, I_PUSH, "ldterm");         /* push ldterm */
7776207
+
7776207
+	return fds;
7776207
+}
7776207
+
7776207
+/* Handle the fact that solaris doesn't have an asprintf */
7776207
+/* pinched from 
7776207
+http://samba.anu.edu.au/rsync/doxygen/head/snprintf_8c-source.html */
7776207
+
7776207
+#ifndef HAVE_VASPRINTF
7776207
+int vasprintf(char **ptr, const char *format, va_list ap)
7776207
+{
7776207
+	int ret;
7776207
+        
7776207
+	ret = vsnprintf(NULL, 0, format, ap);
7776207
+	if (ret <= 0) return ret;
7776207
+
7776207
+	(*ptr) = (char *)malloc(ret+1);
7776207
+	if (!*ptr) return -1;
7776207
+	ret = vsnprintf(*ptr, ret+1, format, ap);
7776207
+
7776207
+	return ret;
7776207
+}
7776207
+#endif
7776207
+
7776207
+
7776207
+#ifndef HAVE_ASPRINTF
7776207
+ int asprintf(char **ptr, const char *format, ...)
7776207
+{
7776207
+	va_list ap;
7776207
+	int ret;
7776207
+        
7776207
+	va_start(ap, format);
7776207
+	ret = vasprintf(ptr, format, ap);
7776207
+	va_end(ap);
7776207
+
7776207
+	return ret;
7776207
+}
7776207
+#endif
7776207
+#endif
7776207
+
7776207
+static int root = 0;			/* if we are root, no password is
7776207
+                                           required */
7776207
+
7776207
+static gint
7776207
+exec_su (gchar *exec_path, gchar *user, gchar *pwd)
7776207
+{
7776207
+	gchar *exec_p, *user_p;  /* command to execute, user name */
7776207
+	pid_t pid;
7776207
+	int t_fd;
7776207
+	
7776207
+	exec_p = g_strdup (exec_path);
7776207
+
7776207
+#if 0
7776207
+	if (asprintf (&exec_p, "%s&", exec_path) < 0) {
7776207
+		perror ("Unable to allocate memory chunk");
7776207
+		g_free (exec_p);
7776207
+		return 0;
7776207
+	}
7776207
+#endif
7776207
+
7776207
+	user_p = (user ? user : "root");
7776207
+
7776207
+	if ((pwd == NULL) || (*pwd == '\0')) {
7776207
+		g_free (exec_p);
7776207
+		return 0;
7776207
+	}
7776207
+
7776207
+	/*
7776207
+	 * Make su think we're sending the password from a terminal:
7776207
+	 */
7776207
+
7776207
+	if (((t_fd = OPEN_TTY()) < 0) || (grantpt(t_fd) < 0) || (unlockpt(t_fd) < 0)) {
7776207
+		fprintf (stderr, "Unable to open a terminal\n");
7776207
+		ABORT (root);
7776207
+	}
7776207
+
7776207
+	if ((pid = fork()) < 0) {
7776207
+		perror ("Unable to fork a new process");
7776207
+		ABORT (root);
7776207
+	}
7776207
+
7776207
+	if (pid > 0) {			/* parent process */
7776207
+		int status;
7776207
+
7776207
+		sleep(1);
7776207
+
7776207
+		/* su(1) won't want a password if we're already root.
7776207
+		 */
7776207
+		if (root == 0) {
7776207
+			write (t_fd, pwd, strlen(pwd));
7776207
+
7776207
+			/* Need the \n to flush the password */
7776207
+			write (t_fd, "\n", 1);
7776207
+		}
7776207
+
7776207
+		waitpid (pid, &status, 0);
7776207
+
7776207
+		if (WIFEXITED (status) && WEXITSTATUS (status) && (WEXITSTATUS(status) < 255)) {
7776207
+/*			error_box (_("Incorrect password.")); */
7776207
+			g_free (exec_p);
7776207
+			return -1;
7776207
+		}
7776207
+		else {
7776207
+			memset (pwd, 0, strlen (pwd));
7776207
+		}
7776207
+	}
7776207
+	else {				/* child process */
7776207
+		struct passwd *pw;
7776207
+		char *env, *home, *pts;
7776207
+
7776207
+		/* We have rights to run X (obviously).  We need to ensure the
7776207
+		 * destination user has the right stuff in the environment
7776207
+		 * to be able to continue to run X.
7776207
+		 * su will change $HOME to the new users home, so we will
7776207
+		 * need an XAUTHORITY / ICEAUTHORITY pointing to the
7776207
+		 * authorization files.
7776207
+		 */
7776207
+
7776207
+		if ((home = getenv ("HOME")) == NULL) {
7776207
+			if ((env = getenv ("USER")) == NULL)
7776207
+				pw = getpwuid(getuid());
7776207
+			else
7776207
+				pw = getpwnam(env);
7776207
+			if (pw)
7776207
+				home = pw->pw_dir;
7776207
+			else {
7776207
+				perror ("Unable to find home directory");
7776207
+				_exit (-1);
7776207
+			}
7776207
+		}
7776207
+
7776207
+		if ((env = getenv ("XAUTHORITY")) == NULL) {
7776207
+			if (asprintf (&env, "XAUTHORITY=%s/.Xauthority", home) > 0)
7776207
+				putenv (env);
7776207
+			else {
7776207
+				perror ("Unable to allocate memory chunk");
7776207
+				_exit (-1);
7776207
+			}
7776207
+		}
7776207
+
7776207
+		if ((env = getenv ("ICEAUTHORITY")) == NULL) {
7776207
+			if (asprintf (&env, "ICEAUTHORITY=%s/.ICEauthority", home) > 0)
7776207
+				putenv (env);
7776207
+			else {
7776207
+				perror ("Unable to allocate memory chunk");
7776207
+				_exit (-1);
7776207
+			}
7776207
+		}
7776207
+
7776207
+		if(((pts = ptsname(t_fd)) == NULL) || ((t_fd = open(pts, O_RDWR | O_NOCTTY)) < 0)) {
7776207
+			perror ("Unable to open pseudo slave terminal");
7776207
+			_exit (-1);
7776207
+		}
7776207
+		dup2 (t_fd, 0);
7776207
+
7776207
+#if 0
7776207
+		freopen ("/dev/null", "w", stderr);
7776207
+		freopen ("/dev/null", "w", stdout);
7776207
+#endif
7776207
+
7776207
+		execlp ("su", "su", "-m", user_p, "-c", exec_p, NULL);
7776207
+		_exit (0);
7776207
+		
7776207
+	}
7776207
+	
7776207
+	g_free (exec_p);
7776207
+
7776207
+	return 0;
7776207
+}
7776207
+
7776207
+gint
7776207
+su_run_with_password (gchar *exec_path, gchar *password)
7776207
+{
7776207
+	return exec_su (exec_path, "root", password);
7776207
+}
1c86b90
+
7776207
+#if 1
7776207
 void _procman_array_gettext_init(const char * strings[], size_t n)
7776207
 {
7776207
 	size_t i;
1c86b90
@@ -15,3 +299,4 @@
7776207
 			strings[i] = _(strings[i]);
7776207
 	}
7776207
 }
7776207
+#endif