summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorBrian Cameron <brian.cameron@sun.com>2006-10-30 18:14:49 +0000
committerBrian Cameron <bcameron@src.gnome.org>2006-10-30 18:14:49 +0000
commita6865f4468460545f14784c8b7063ebbffbb2100 (patch)
treea91481d2dd6cbbb43794aff85ee5aebc9baec22f /daemon
parent48320ec6774f9cb010631e636871ce5f167a093d (diff)
downloadgdm-a6865f4468460545f14784c8b7063ebbffbb2100.tar.gz
Add new QUERY_CUSTOM_CMD_LABELS and QUERY_CUSTOM_CMD_NO_RESTART_STATUS
2006-10-30 Brian Cameron <brian.cameron@sun.com> * config/gdm.conf.in, daemon/gdm.c, daemon/gdm.h, daemon/gdmconfig.c, docs/C/gdm.xml, gui/gdmlogin.c, gui/greeter/greeter.c, gui/greeter/greeter_item.c, gui/greeter/greeter_configuration.h, gui/greeter/greeter_system.c: Add new QUERY_CUSTOM_CMD_LABELS and QUERY_CUSTOM_CMD_NO_RESTART_STATUS commands and the new CustomCommandIsPersistent[0-9]
Diffstat (limited to 'daemon')
-rw-r--r--daemon/gdm.c172
-rw-r--r--daemon/gdm.h34
-rw-r--r--daemon/gdmconfig.c108
3 files changed, 220 insertions, 94 deletions
diff --git a/daemon/gdm.c b/daemon/gdm.c
index 33823963..10cd91e9 100644
--- a/daemon/gdm.c
+++ b/daemon/gdm.c
@@ -714,10 +714,10 @@ static void
custom_cmd (long cmd_id)
{
if (cmd_id < 0 || cmd_id >= GDM_CUSTOM_COMMAND_MAX) {
- /* We are just feeling very paranoid */
- gdm_error (_("custom_cmd: Custom command index %ld outside permitted range [0,%d)"),
- cmd_id, GDM_CUSTOM_COMMAND_MAX);
- return;
+ /* We are just feeling very paranoid */
+ gdm_error (_("custom_cmd: Custom command index %ld outside permitted range [0,%d)"),
+ cmd_id, GDM_CUSTOM_COMMAND_MAX);
+ return;
}
gchar * key_string = g_strdup_printf (_("%s%ld="), GDM_KEY_CUSTOM_CMD_NO_RESTART_TEMPLATE, cmd_id);
@@ -725,7 +725,7 @@ custom_cmd (long cmd_id)
custom_cmd_no_restart (cmd_id);
else
custom_cmd_restart (cmd_id);
-
+
g_free(key_string);
}
@@ -747,7 +747,7 @@ custom_cmd_restart (long cmd_id)
argv = ve_split (gdm_get_value_string (key_string));
g_free(key_string);
if (argv != NULL && argv[0] != NULL)
- VE_IGNORE_EINTR (execv (argv[0], argv));
+ VE_IGNORE_EINTR (execv (argv[0], argv));
g_strfreev (argv);
@@ -769,32 +769,32 @@ custom_cmd_no_restart (long cmd_id)
return;
}
else if (pid == 0) {
- /* child */
- char **argv;
- gchar * key_string = g_strdup_printf (_("%s%ld="), GDM_KEY_CUSTOM_CMD_TEMPLATE, cmd_id);
- argv = ve_split (gdm_get_value_string (key_string));
- g_free(key_string);
- if (argv != NULL && argv[0] != NULL)
- VE_IGNORE_EINTR (execv (argv[0], argv));
+ /* child */
+ char **argv;
+ gchar * key_string = g_strdup_printf (_("%s%ld="), GDM_KEY_CUSTOM_CMD_TEMPLATE, cmd_id);
+ argv = ve_split (gdm_get_value_string (key_string));
+ g_free(key_string);
+ if (argv != NULL && argv[0] != NULL)
+ VE_IGNORE_EINTR (execv (argv[0], argv));
- g_strfreev (argv);
-
- gdm_error (_("%s: Execution of custom command failed: %s"),
- "gdm_child_action", strerror (errno));
-
- _exit (0);
+ g_strfreev (argv);
+
+ gdm_error (_("%s: Execution of custom command failed: %s"),
+ "gdm_child_action", strerror (errno));
+
+ _exit (0);
}
else {
- /* parent */
- gint exitstatus = 0, status;
- pid_t p_stat = waitpid (1, &exitstatus, WNOHANG);
- if(p_stat > 0){
- if G_LIKELY (WIFEXITED (exitstatus)){
- status = WEXITSTATUS (exitstatus);
- gdm_debug (_("custom_cmd: child %d returned %d"), p_stat, status);
- }
- return;
- }
+ /* parent */
+ gint exitstatus = 0, status;
+ pid_t p_stat = waitpid (1, &exitstatus, WNOHANG);
+ if (p_stat > 0) {
+ if G_LIKELY (WIFEXITED (exitstatus)){
+ status = WEXITSTATUS (exitstatus);
+ gdm_debug (_("custom_cmd: child %d returned %d"), p_stat, status);
+ }
+ return;
+ }
}
}
@@ -1173,7 +1173,7 @@ gdm_do_logout_action (GdmLogoutAction logout_action)
check for the range of values */
if (logout_action >= GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST &&
logout_action <= GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST)
- custom_cmd (logout_action - GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST);
+ custom_cmd (logout_action - GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST);
break;
}
}
@@ -2979,6 +2979,8 @@ handle_dynamic_server (GdmConnection *conn, int type, gchar *key)
static void
gdm_handle_user_message (GdmConnection *conn, const gchar *msg, gpointer data)
{
+ gint i;
+
gdm_debug ("Handling user message: '%s'", msg);
if (gdm_connection_get_message_count (conn) > GDM_SUP_MAX_MESSAGES) {
@@ -3372,23 +3374,109 @@ gdm_handle_user_message (GdmConnection *conn, const gchar *msg, gpointer data)
sep = ";";
}
- register int i = 0;
- for (; i < GDM_CUSTOM_COMMAND_MAX; i++) {
- gchar *key_string = NULL;
- key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
- if (sysmenu && disp->attached &&
- ! ve_string_empty (gdm_get_value_string (key_string))) {
- g_string_append_printf (msg, "%s%s%d", sep, GDM_SUP_LOGOUT_ACTION_CUSTOM_CMD_TEMPLATE, i);
- if (logout_action == (GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST + i))
- g_string_append (msg, "!");
- sep = ";";
- }
- g_free(key_string);
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ gchar *key_string = NULL;
+ key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ if (sysmenu && disp->attached &&
+ ! ve_string_empty (gdm_get_value_string (key_string))) {
+ g_free (key_string);
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE, i);
+ if (gdm_get_value_bool (key_string)) {
+ g_string_append_printf (msg, "%s%s%d", sep, GDM_SUP_LOGOUT_ACTION_CUSTOM_CMD_TEMPLATE, i);
+ if (logout_action == (GDM_LOGOUT_ACTION_CUSTOM_CMD_FIRST + i))
+ g_string_append (msg, "!");
+ sep = ";";
+ }
+ }
+ g_free(key_string);
}
g_string_append (msg, "\n");
gdm_connection_write (conn, msg->str);
g_string_free (msg, TRUE);
+ } else if (strcmp (msg, GDM_SUP_QUERY_CUSTOM_CMD_LABELS) == 0) {
+ GdmDisplay *disp;
+ GString *msg;
+ const gchar *sep = " ";
+ gboolean sysmenu;
+
+ disp = gdm_connection_get_display (conn);
+ sysmenu = gdm_get_value_bool_per_display (disp->name, GDM_KEY_SYSTEM_MENU);
+
+ /* Only allow locally authenticated connections */
+ if ( ! GDM_CONN_AUTHENTICATED (conn) ||
+ disp == NULL) {
+ gdm_info (_("%s request denied: "
+ "Not authenticated"), "QUERY_LOGOUT_ACTION");
+ gdm_connection_write (conn,
+ "ERROR 100 Not authenticated\n");
+ return;
+ }
+
+ msg = g_string_new ("OK");
+
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ gchar *key_string = NULL;
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ if (sysmenu && disp->attached &&
+ ! ve_string_empty (gdm_get_value_string (key_string))) {
+ g_free (key_string);
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE, i);
+ if (gdm_get_value_bool (key_string)) {
+ g_free (key_string);
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_LABEL_TEMPLATE, i);
+ g_string_append_printf (msg, "%s%s", sep, gdm_get_value_string (key_string));
+ sep = ";";
+ }
+ }
+ g_free(key_string);
+ }
+
+ g_string_append (msg, "\n");
+ gdm_connection_write (conn, msg->str);
+ g_string_free (msg, TRUE);
+ } else if (strcmp (msg, GDM_SUP_QUERY_CUSTOM_CMD_NO_RESTART_STATUS) == 0) {
+ GdmDisplay *disp;
+ GString *msg;
+ gboolean sysmenu;
+
+ disp = gdm_connection_get_display (conn);
+ sysmenu = gdm_get_value_bool_per_display (disp->name, GDM_KEY_SYSTEM_MENU);
+
+ /* Only allow locally authenticated connections */
+ if ( ! GDM_CONN_AUTHENTICATED (conn) ||
+ disp == NULL) {
+ gdm_info (_("%s request denied: "
+ "Not authenticated"), "QUERY_LOGOUT_ACTION");
+ gdm_connection_write (conn,
+ "ERROR 100 Not authenticated\n");
+ return;
+ }
+
+ msg = g_string_new ("OK ");
+
+ unsigned long no_restart_status_flag = 0; /* we can store up-to 32 commands this way */
+
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ gchar *key_string = NULL;
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ if (sysmenu && disp->attached &&
+ ! ve_string_empty (gdm_get_value_string (key_string))) {
+ g_free (key_string);
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE, i);
+ if (gdm_get_value_bool (key_string)) {
+ g_free (key_string);
+ key_string = g_strdup_printf(_("%s%d="), GDM_KEY_CUSTOM_CMD_NO_RESTART_TEMPLATE, i);
+ if(gdm_get_value_bool (key_string))
+ no_restart_status_flag |= (1 << i);
+ }
+ }
+ g_free(key_string);
+ }
+
+ g_string_append_printf (msg, "%ld\n", no_restart_status_flag);
+ gdm_connection_write (conn, msg->str);
+ g_string_free (msg, TRUE);
} else if (strncmp (msg, GDM_SUP_SET_LOGOUT_ACTION " ",
strlen (GDM_SUP_SET_LOGOUT_ACTION " ")) == 0) {
const gchar *action =
diff --git a/daemon/gdm.h b/daemon/gdm.h
index 21a311df..765e2aff 100644
--- a/daemon/gdm.h
+++ b/daemon/gdm.h
@@ -241,6 +241,7 @@ enum {
#define GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE "customcommand/CustomCommandText"
#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_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/"
@@ -452,6 +453,7 @@ struct _GdmCustomCmd {
gchar *command_text; /* warning dialog text */
gchar *command_tooltip; /* tooltip string */
gboolean command_no_restart; /* no restart flag */
+ gboolean command_is_persistent; /* persistence flag */
};
#define GDM_CUSTOM_COMMAND_MAX 10 /* maximum number of supported custom commands */
@@ -1177,6 +1179,38 @@ void gdm_final_cleanup (void);
* 200 = Too many messages
* 999 = Unknown error
*/
+#define GDM_SUP_QUERY_CUSTOM_CMD_LABELS "QUERY_CUSTOM_CMD_LABELS" /* None */
+/* QUERY_CUSTOM_CMD_LABELS: Query labels belonging to exported custom commands
+ * Only supported on connections that passed
+ * AUTH_LOCAL.
+ * Supported since: 2.5.90.0
+ * Answers:
+ * OK <label1>;<label2>;...
+ * Where labelX is one of the labels belonging to CUSTOM_CMDX (where X in [0,GDM_CUSTOM_COMMAND_MAX)).
+ * An empty list can also be returned if none of the custom commands are
+ * exported outside login manager (no CustomCommandIsPersistent options are set to true).
+ * ERROR <err number> <english error description>
+ * 0 = Not implemented
+ * 100 = Not authenticated
+ * 200 = Too many messages
+ * 999 = Unknown error
+ */
+#define GDM_SUP_QUERY_CUSTOM_CMD_NO_RESTART_STATUS "QUERY_CUSTOM_CMD_NO_RESTART_STATUS" /* None */
+/* QUERY_CUSTOM_CMD_NO_RESTART_STATUS: Query NoRestart config options for each of custom commands
+ * Only supported on connections that passed
+ * AUTH_LOCAL.
+ * Supported since: 2.5.90.0
+ * Answers:
+ * OK <status>
+ * Where each bit of the status represents NoRestart value for each of the custom commands.
+ * bit on (1): NoRestart = true,
+ * bit off (0): NoRestart = false.
+ * ERROR <err number> <english error description>
+ * 0 = Not implemented
+ * 100 = Not authenticated
+ * 200 = Too many messages
+ * 999 = Unknown error
+ */
#define GDM_SUP_SET_LOGOUT_ACTION "SET_LOGOUT_ACTION" /* <action> */
/* SET_LOGOUT_ACTION: Tell the daemon to halt/restart/suspend after
* slave process exits. Only supported on
diff --git a/daemon/gdmconfig.c b/daemon/gdmconfig.c
index 0aefacac..6a179dbe 100644
--- a/daemon/gdmconfig.c
+++ b/daemon/gdmconfig.c
@@ -345,6 +345,8 @@ is_key (const gchar *key1, const gchar *key2)
static void
gdm_config_init (void)
{
+ gint i;
+
type_hash = g_hash_table_new (g_str_hash, g_str_equal);
val_hash = g_hash_table_new (g_str_hash, g_str_equal);
realkey_hash = g_hash_table_new (g_str_hash, g_str_equal);
@@ -509,33 +511,36 @@ gdm_config_init (void)
/* custom command string values */
GdmCustomCommands = g_new0 (GdmCustomCmd, GDM_CUSTOM_COMMAND_MAX);
- register int i = 0;
gchar *key_string = NULL;
- for (; i < GDM_CUSTOM_COMMAND_MAX; i++) {
- /* For each possible custom command */
- key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
- GdmCustomCommands[i].command = NULL;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command, &string_type);
-
- key_string = g_strdup_printf (_("%s%d=_Custom%d"), GDM_KEY_CUSTOM_CMD_LABEL_TEMPLATE, i, i);
- GdmCustomCommands[i].command_label = NULL;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_label, &string_type);
-
- key_string = g_strdup_printf (_("%s%d=Execute _custom command %d"), GDM_KEY_CUSTOM_CMD_LR_LABEL_TEMPLATE, i, i);
- GdmCustomCommands[i].command_lr_label = NULL;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_lr_label, &string_type);
-
- key_string = g_strdup_printf (_("%s%d=Are you sure?"), GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE, i);
- GdmCustomCommands[i].command_text = NULL;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_text, &string_type);
-
- key_string = g_strdup_printf (_("%s%d=Execute custom command %d"), GDM_KEY_CUSTOM_CMD_TOOLTIP_TEMPLATE, i, i);
- GdmCustomCommands[i].command_tooltip = NULL;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_tooltip, &string_type);
-
- key_string = g_strdup_printf (_("%s%d=false"), GDM_KEY_CUSTOM_CMD_NO_RESTART_TEMPLATE, i);
- GdmCustomCommands[i].command_no_restart = FALSE;
- gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_no_restart, &bool_type);
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ /* For each possible custom command */
+ key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ GdmCustomCommands[i].command = NULL;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command, &string_type);
+
+ key_string = g_strdup_printf (_("%s%d=Custom_%d"), GDM_KEY_CUSTOM_CMD_LABEL_TEMPLATE, i, i);
+ GdmCustomCommands[i].command_label = NULL;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_label, &string_type);
+
+ key_string = g_strdup_printf (_("%s%d=Execute custom command _%d"), GDM_KEY_CUSTOM_CMD_LR_LABEL_TEMPLATE, i, i);
+ GdmCustomCommands[i].command_lr_label = NULL;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_lr_label, &string_type);
+
+ key_string = g_strdup_printf (_("%s%d=Are you sure?"), GDM_KEY_CUSTOM_CMD_TEXT_TEMPLATE, i);
+ GdmCustomCommands[i].command_text = NULL;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_text, &string_type);
+
+ key_string = g_strdup_printf (_("%s%d=Execute custom command %d"), GDM_KEY_CUSTOM_CMD_TOOLTIP_TEMPLATE, i, i);
+ GdmCustomCommands[i].command_tooltip = NULL;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_tooltip, &string_type);
+
+ key_string = g_strdup_printf (_("%s%d=false"), GDM_KEY_CUSTOM_CMD_NO_RESTART_TEMPLATE, i);
+ GdmCustomCommands[i].command_no_restart = FALSE;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_no_restart, &bool_type);
+
+ key_string = g_strdup_printf(_("%s%d=false"), GDM_KEY_CUSTOM_CMD_IS_PERSISTENT_TEMPLATE, i);
+ GdmCustomCommands[i].command_is_persistent = FALSE;
+ gdm_config_add_hash (key_string, &GdmCustomCommands[i].command_is_persistent, &bool_type);
}
/* int values */
@@ -1059,6 +1064,7 @@ _gdm_set_value_string (gchar *key, gchar *value_in, gboolean doing_update)
gchar *setting_copy = NULL;
gchar *temp_string;
gchar *value;
+ gint i;
if (! ve_string_empty (value_in))
value = value_in;
@@ -1191,23 +1197,21 @@ _gdm_set_value_string (gchar *key, gchar *value_in, gboolean doing_update)
/* All others */
} else {
- register int i = 0;
- gchar * key_string = NULL;
- for (; i < GDM_CUSTOM_COMMAND_MAX; i++) {
- /* For each possible custom command */
- key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
- if(is_key (key, key_string)) {
- if (value != NULL)
- *setting = ve_get_first_working_command (value, FALSE);
- else
- *setting = NULL;
-
- break;
- }
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ gchar * key_string = NULL;
+ /* For each possible custom command */
+ key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ if(is_key (key, key_string)) {
+ if (value != NULL)
+ *setting = ve_get_first_working_command (value, FALSE);
+ else
+ *setting = NULL;
+
+ break;
+ }
+ g_free(key_string);
}
- g_free(key_string);
-
if (value != NULL)
*setting = g_strdup (value);
else {
@@ -1242,18 +1246,18 @@ _gdm_set_value_string (gchar *key, gchar *value_in, gboolean doing_update)
else if (is_key (key, GDM_KEY_TIMED_LOGIN))
notify_displays_string (GDM_NOTIFY_TIMED_LOGIN, *setting);
- register int i = 0;
- gchar * key_string = NULL;
- for (; i < GDM_CUSTOM_COMMAND_MAX; i++) {
- /* For each possible custom command */
- key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
- if (is_key (key, key_string)) {
- g_free(key_string);
- key_string = g_strdup_printf (_("%s%d"), GDM_NOTIFY_CUSTOM_CMD_TEMPLATE, i);
- notify_displays_string (key_string, *setting);
- }
+ for (i = 0; i < GDM_CUSTOM_COMMAND_MAX; i++) {
+ gchar * key_string = NULL;
+ /* For each possible custom command */
+ key_string = g_strdup_printf (_("%s%d="), GDM_KEY_CUSTOM_CMD_TEMPLATE, i);
+ if (is_key (key, key_string)) {
+ g_free(key_string);
+ key_string = g_strdup_printf (_("%s%d"), GDM_NOTIFY_CUSTOM_CMD_TEMPLATE, i);
+ notify_displays_string (key_string, *setting);
+ break;
+ }
+ g_free(key_string);
}
- g_free(key_string);
}
if (setting_copy != NULL)