Index: gui/gdmlogin.c
===================================================================
--- gui/gdmlogin.c	(revision 4992)
+++ gui/gdmlogin.c	(working copy)
@@ -711,15 +711,20 @@
 {	
 	if (data) {
 		int *cmd_id = (int*)data;
-		gchar * key_string = g_strdup_printf ("%s%d=", GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE, *cmd_id);
-		if (gdm_wm_warn_dialog (
-			    gdm_config_get_string (key_string) , "", GTK_STOCK_OK, NULL, TRUE) == GTK_RESPONSE_YES) {
+		const gchar *prompt;
+		gchar * key_string;
+		key_string = g_strdup_printf ("%s%d=", GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE, *cmd_id);
+		prompt = gdm_config_get_string (key_string);
+		g_free (key_string);		
+		gdm_common_debug("using prompt %s for cmd_id %d", prompt, *cmd_id);
+		if (strcmp(prompt, "none") == 0 || gdm_wm_warn_dialog (
+			     prompt, "", GTK_STOCK_OK, NULL, TRUE) == GTK_RESPONSE_YES) {
 			
+			gdm_common_debug("running custom command %d", *cmd_id);
 			printf ("%c%c%c%d\n", STX, BEL, GDM_INTERRUPT_CUSTOM_CMD, *cmd_id);
 			fflush (stdout);
 		}
 		
-		g_free (key_string);		
 	}
 }
 
Index: gui/greeter/greeter_system.c
===================================================================
--- gui/greeter/greeter_system.c	(revision 4992)
+++ gui/greeter/greeter_system.c	(working copy)
@@ -94,12 +94,13 @@
         if (data) {
 		gint *cmd_id = (gint*)data;
 	        gchar * key_string = g_strdup_printf ("%s%d=", GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE, *cmd_id);
-		if (gdm_wm_warn_dialog (gdm_config_get_string (key_string) , "", 
+		const char *query = gdm_config_get_string (key_string); 
+		g_free (key_string);		
+		if (strcmp(query, "none") == 0 || gdm_wm_warn_dialog (query, "", 
 					GTK_STOCK_OK, NULL, TRUE) == GTK_RESPONSE_YES) {
 		        printf ("%c%c%c%d\n", STX, BEL, GDM_INTERRUPT_CUSTOM_CMD, *cmd_id);
 			fflush (stdout);
 		}
-		g_free (key_string);		
 	}
 }
 
Index: daemon/gdm-daemon-config-entries.h
===================================================================
--- daemon/gdm-daemon-config-entries.h	(revision 4992)
+++ daemon/gdm-daemon-config-entries.h	(working copy)
@@ -72,6 +72,7 @@
 	GDM_ID_CUSTOM_CMD_TOOLTIP_TEMPLATE,
 	GDM_ID_CUSTOM_CMD_NO_RESTART_TEMPLATE,
 	GDM_ID_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE,
+	GDM_ID_CUSTOM_CMD_IS_UIPRIV_TEMPLATE,
 	GDM_ID_ROOT_PATH,
 	GDM_ID_SERV_AUTHDIR,
 	GDM_ID_SESSION_DESKTOP_DIR,
@@ -481,6 +482,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip0", GDM_CONFIG_VALUE_STRING, "Execute custom command 0", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart0", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent0", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv0", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand1", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel1", GDM_CONFIG_VALUE_STRING, "Custom_1", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel1", GDM_CONFIG_VALUE_STRING, "Execute custom command _1", GDM_ID_NONE },
@@ -488,6 +490,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip1", GDM_CONFIG_VALUE_STRING, "Execute custom command 1", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart1", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent1", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv1", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand2", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel2", GDM_CONFIG_VALUE_STRING, "Custom_2", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel2", GDM_CONFIG_VALUE_STRING, "Execute custom command _2", GDM_ID_NONE },
@@ -495,6 +498,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip2", GDM_CONFIG_VALUE_STRING, "Execute custom command 2", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart2", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent2", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv2", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand3", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel3", GDM_CONFIG_VALUE_STRING, "Custom_3", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel3", GDM_CONFIG_VALUE_STRING, "Execute custom command _3", GDM_ID_NONE },
@@ -502,6 +506,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip3", GDM_CONFIG_VALUE_STRING, "Execute custom command 3", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart3", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent3", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv3", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand4", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel4", GDM_CONFIG_VALUE_STRING, "Custom_4", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel4", GDM_CONFIG_VALUE_STRING, "Execute custom command _4", GDM_ID_NONE },
@@ -509,6 +514,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip4", GDM_CONFIG_VALUE_STRING, "Execute custom command 4", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart4", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent4", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv4", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand5", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel5", GDM_CONFIG_VALUE_STRING, "Custom_5", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel5", GDM_CONFIG_VALUE_STRING, "Execute custom command _5", GDM_ID_NONE },
@@ -516,6 +522,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip5", GDM_CONFIG_VALUE_STRING, "Execute custom command 5", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart5", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent5", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv5", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand6", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel6", GDM_CONFIG_VALUE_STRING, "Custom_6", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel6", GDM_CONFIG_VALUE_STRING, "Execute custom command _6", GDM_ID_NONE },
@@ -523,6 +530,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip6", GDM_CONFIG_VALUE_STRING, "Execute custom command 6", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart6", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent6", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv6", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand7", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel7", GDM_CONFIG_VALUE_STRING, "Custom_7", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel7", GDM_CONFIG_VALUE_STRING, "Execute custom command _7", GDM_ID_NONE },
@@ -530,6 +538,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip7", GDM_CONFIG_VALUE_STRING, "Execute custom command 7", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart7", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent7", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv7", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand8", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel8", GDM_CONFIG_VALUE_STRING, "Custom_8", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel8", GDM_CONFIG_VALUE_STRING, "Execute custom command _8", GDM_ID_NONE },
@@ -537,6 +546,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip8", GDM_CONFIG_VALUE_STRING, "Execute custom command 8", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart8", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent8", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv8", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommand9", GDM_CONFIG_VALUE_STRING, NULL, GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLabel9", GDM_CONFIG_VALUE_STRING, "Custom_9", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandLRLabel9", GDM_CONFIG_VALUE_STRING, "Execute custom command _9", GDM_ID_NONE },
@@ -544,6 +554,7 @@
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandTooltip9", GDM_CONFIG_VALUE_STRING, "Execute custom command 9", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandNoRestart9", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsPersistent9", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
+	{ GDM_CONFIG_GROUP_CUSTOM_CMD, "CustomCommandIsUiPriv9", GDM_CONFIG_VALUE_BOOL, "false", GDM_ID_NONE },
 
 	{ NULL }
 };
Index: daemon/gdm-daemon-config-keys.h
===================================================================
--- daemon/gdm-daemon-config-keys.h	(revision 4992)
+++ daemon/gdm-daemon-config-keys.h	(working copy)
@@ -55,6 +55,7 @@
 #define GDM_KEY_CUSTOM_CMD_TOOLTIP_TEMPLATE "customcommand/CustomCommandTooltip"
 #define GDM_KEY_CUSTOM_CMD_NO_RESTART_TEMPLATE "customcommand/CustomCommandNoRestart"
 #define GDM_KEY_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE "customcommand/CustomCommandIsPersistent"
+#define GDM_KEY_CUSTOM_CMD_IS_UIPRIV_TEMPLATE "customcommand/CustomCommandIsUiPriv"
 #define GDM_KEY_ROOT_PATH "daemon/RootPath=/sbin:/usr/sbin:" GDM_USER_PATH
 #define GDM_KEY_SERV_AUTHDIR "daemon/ServAuthDir=" AUTHDIR
 #define GDM_KEY_SESSION_DESKTOP_DIR "daemon/SessionDesktopDir=/etc/X11/sessions/:" DMCONFDIR "/Sessions/:" DATADIR "/gdm/BuiltInSessions/:" DATADIR "/xsessions/"
Index: daemon/slave.c
===================================================================
--- daemon/slave.c	(revision 4992)
+++ daemon/slave.c	(working copy)
@@ -113,6 +113,9 @@
 static gboolean do_configurator        = FALSE; /* If this is true, login as 
 					         * root and start the
                                                  * configurator */
+static gint     do_uipriv_custom_cmd   = -1;    /* If this is greater than 0, log in
+                                                 * as root and exec custom command
+                                                 */
 static gboolean do_cancel              = FALSE; /* If this is true, go back to
                                                    username entry & unselect
                                                    face browser (if present) */
@@ -1825,25 +1828,14 @@
 	}
 }
 
-static void
-run_config (GdmDisplay *display, struct passwd *pwent)
+static gboolean
+run_external_program (GdmDisplay *display, 
+		      struct passwd *pwent,
+		      const char *config_key,
+		      const char *fallback_exec)
 {
 	pid_t pid;
 
-	/* Lets check if custom.conf exists. If not there
-	   is no point in launching gdmsetup as it will fail.
-	   We don't need to worry about defaults.conf as
-	   the daemon wont start without it
-	*/
-	if (gdm_daemon_config_get_custom_config_file () == NULL) {
-		gdm_errorgui_error_box (d,
-			       GTK_MESSAGE_ERROR,
-			       _("Could not access configuration file (custom.conf). "
-				 "Make sure that the file exists before launching "
-				 " login manager config utility."));
-		return;
-	}
-
 	/* Set the busy cursor */
 	if (d->dsp != NULL) {
 		Cursor xcursor = XCreateFontCursor (d->dsp, GDK_WATCH);
@@ -1854,7 +1846,7 @@
 		XSync (d->dsp, False);
 	}
 
-	g_debug ("Forking GDM configuration process");
+	g_debug ("Forking GDM process to exec %s", config_key);
 
 	gdm_sigchld_block_push ();
 	gdm_sigterm_block_push ();
@@ -1878,7 +1870,7 @@
 		XFreeCursor (d->dsp, xcursor);
 		XSync (d->dsp, False);
 
-		return;
+		return FALSE;
 	}
 
 	if (pid == 0) {
@@ -1897,6 +1889,7 @@
 
 		/* setup environment */
 		gdm_restoreenv ();
+		/* FIXME - this segfaults */
 		gdm_reset_locale ();
 
 		/* root here */
@@ -1904,11 +1897,13 @@
 		g_setenv ("DISPLAY", display->name, TRUE);
 		if (d->windowpath)
 			g_setenv ("WINDOWPATH", d->windowpath, TRUE);
-		g_setenv ("LOGNAME", pwent->pw_name, TRUE);
-		g_setenv ("USER", pwent->pw_name, TRUE);
-		g_setenv ("USERNAME", pwent->pw_name, TRUE);
-		g_setenv ("HOME", pwent->pw_dir, TRUE);
-		g_setenv ("SHELL", pwent->pw_shell, TRUE);
+		if (pwent) {
+			g_setenv ("LOGNAME", pwent->pw_name, TRUE);
+			g_setenv ("USER", pwent->pw_name, TRUE);
+			g_setenv ("USERNAME", pwent->pw_name, TRUE);
+			g_setenv ("HOME", pwent->pw_dir, TRUE);
+			g_setenv ("SHELL", pwent->pw_shell, TRUE);
+		}
 		g_setenv ("PATH", gdm_daemon_config_get_value_string (GDM_KEY_ROOT_PATH), TRUE);
 		g_setenv ("RUNNING_UNDER_GDM", "true", TRUE);
 		if ( ! ve_string_empty (display->theme_name))
@@ -1926,12 +1921,16 @@
 
 		gdm_log_init ();
 
-		VE_IGNORE_EINTR (g_chdir (pwent->pw_dir));
-		if G_UNLIKELY (errno != 0)
+		if (pwent) {
+			VE_IGNORE_EINTR (g_chdir (pwent->pw_dir));
+			if G_UNLIKELY (errno != 0)
+			      VE_IGNORE_EINTR (g_chdir ("/"));
+		} else {
 			VE_IGNORE_EINTR (g_chdir ("/"));
+		}
 
 		/* exec the configurator */
-		s = gdm_daemon_config_get_value_string (GDM_KEY_CONFIGURATOR);
+		s = gdm_daemon_config_get_value_string ((char*)config_key);
 		if (s != NULL) {
 			g_shell_parse_argv (s, NULL, &argv, NULL);
 		}
@@ -1942,25 +1941,31 @@
 			VE_IGNORE_EINTR (execv (argv[0], argv));
 		}
 
+		g_error (_("%s: Failed starting: %s"),
+			 "run_external_program",
+			 argv[0]);
+
 		g_strfreev (argv);
 
-		gdm_errorgui_error_box (d,
-					GTK_MESSAGE_ERROR,
-					_("Could not execute the configuration "
-					  "application.  Make sure its path is set "
-					  "correctly in the configuration file.  "
-					  "Attempting to start it from the default "
-					  "location."));
-		s = LIBEXECDIR "/gdmsetup --disable-sound --disable-crash-dialog";
-		argv = NULL;
-		g_shell_parse_argv (s, NULL, &argv, NULL);
+		if (fallback_exec) {
+			gdm_errorgui_error_box (d,
+						GTK_MESSAGE_ERROR,
+						_("Could not execute the configuration "
+						  "application.  Make sure its path is set "
+						  "correctly in the configuration file.  "
+						  "Attempting to start it from the default "
+						  "location."));
+			s = fallback_exec;
+			argv = NULL;
+			g_shell_parse_argv (s, NULL, &argv, NULL);
+			
+			if (g_access (argv[0], X_OK) == 0) {
+				VE_IGNORE_EINTR (execv (argv[0], argv));
+			}
 
-		if (g_access (argv[0], X_OK) == 0) {
-			VE_IGNORE_EINTR (execv (argv[0], argv));
+			g_strfreev (argv);
 		}
 
-		g_strfreev (argv);
-
 		gdm_errorgui_error_box (d,
 					GTK_MESSAGE_ERROR,
 					_("Could not execute the configuration "
@@ -1985,9 +1990,42 @@
 		/* this will clean up the sensitivity property */
 		gdm_slave_sensitize_config ();
 	}
+	return TRUE;
 }
 
 static void
+run_config (GdmDisplay *display, struct passwd *pwent)
+{
+	/* Lets check if custom.conf exists. If not there
+	   is no point in launching gdmsetup as it will fail.
+	   We don't need to worry about defaults.conf as
+	   the daemon wont start without it
+	*/
+	if (gdm_daemon_config_get_custom_config_file () == NULL) {
+		gdm_errorgui_error_box (d,
+			       GTK_MESSAGE_ERROR,
+			       _("Could not access configuration file (custom.conf). "
+				 "Make sure that the file exists before launching "
+				 " login manager config utility."));
+		return;
+	}
+
+	run_external_program (display, pwent,
+			      GDM_KEY_CONFIGURATOR, 
+			      LIBEXECDIR "/gdmsetup --disable-sound --disable-crash-dialog");
+}
+
+static void
+run_uipriv_custom_cmd (GdmDisplay *display, guint id)
+{
+	char *key_string;
+
+	key_string = g_strdup_printf ("%s%u", GDM_KEY_CUSTOM_CMD_TEMPLATE, id);
+	run_external_program (display, NULL, key_string, NULL);
+	g_free (key_string);
+}
+
+static void
 restart_the_greeter (void)
 {
 	do_restart_greeter = FALSE;
@@ -2082,6 +2120,7 @@
 		/* init to a sane value */
 		do_timed_login = FALSE;
 		do_configurator = FALSE;
+		do_uipriv_custom_cmd = -1;
 		do_cancel = FALSE;
 
 		if G_UNLIKELY (do_restart_greeter) {
@@ -2123,8 +2162,40 @@
 		}
 
 		check_notifies_now ();
+		
+		if G_UNLIKELY (do_uipriv_custom_cmd >= 0) {
+			uid_t old = geteuid ();
+			gid_t oldg = getegid ();
+			gint cmd_id = do_uipriv_custom_cmd;
 
-		if G_UNLIKELY (do_configurator) {
+			g_debug ("gdm_slave_wait_for_login: executing uipriv: %d", cmd_id);
+
+			do_uipriv_custom_cmd = -1;
+
+			if (old != 0) {
+				NEVER_FAILS_seteuid (0);
+				NEVER_FAILS_setegid (gdm_daemon_config_get_gdmgid ());
+			}
+
+			g_free (login);
+			login = NULL;
+			gdm_slave_greeter_ctl_no_ret (GDM_ERRBOX, "");
+
+			check_notifies_now ();
+			restart_greeter_now = TRUE;
+				
+			gdm_debug ("gdm_slave_wait_for_login: Running custom command %d...", cmd_id);
+			run_uipriv_custom_cmd (d, cmd_id);
+			gdm_debug ("gdm_slave_wait_for_login: Custom command %d finished...", cmd_id);
+
+			restart_greeter_now = FALSE;
+
+			gdm_verify_cleanup (d);
+
+			if (old != 0) {
+				NEVER_FAILS_root_set_euid_egid (old, oldg);
+			}
+		} else if G_UNLIKELY (do_configurator) {
 			struct passwd *pwent;
 			gboolean oldAllowRoot;
 
@@ -5159,12 +5230,31 @@
 		case GDM_INTERRUPT_CUSTOM_CMD:
 			if (d->attached &&
 			    ! ve_string_empty (&msg[2])) {
-				gchar *message = g_strdup_printf ("%s %ld %s", 
-								  GDM_SOP_CUSTOM_CMD,
-								  (long)getpid (), &msg[2]);
+				gboolean is_uipriv;
+				gchar *key_string;
+				long cmd_id;
 
-				gdm_slave_send (message, TRUE);
-				g_free (message);
+				gdm_debug ("check_for_interruption: custom command '%s'", &msg[2]);
+				if (sscanf (&msg[2], "%ld", &cmd_id) != 1)
+					return TRUE;
+				if (cmd_id < 0 || cmd_id >= GDM_CUSTOM_COMMAND_MAX)
+					return TRUE;
+				
+				key_string = g_strdup_printf ("%s%ld", GDM_KEY_CUSTOM_CMD_IS_UIPRIV_TEMPLATE, cmd_id);
+				is_uipriv = gdm_daemon_config_get_value_bool (key_string);
+				g_free (key_string);
+				gdm_debug ("check_for_interruption: custom command is uipriv: %s", is_uipriv ? "TRUE" : "FALSE");
+				if (!is_uipriv) {
+					gchar *message = g_strdup_printf ("%s %ld %s", 
+									  GDM_SOP_CUSTOM_CMD,
+									  (long)getpid (), &msg[2]);
+					
+					gdm_slave_send (message, TRUE);
+					g_free (message);
+				} else {
+					do_uipriv_custom_cmd = cmd_id;
+					break;
+				}
 			}
 			return TRUE;
 		case GDM_INTERRUPT_THEME:
@@ -5597,6 +5687,7 @@
 {
 	if (do_timed_login ||
 	    do_configurator ||
+	    do_uipriv_custom_cmd >= 0 ||
 	    do_restart_greeter ||
 	    do_cancel)
 		return FALSE;
