diff options
author | George Lebl <jirka@5z.com> | 2002-05-31 22:47:37 +0000 |
---|---|---|
committer | George Lebl <jirka@src.gnome.org> | 2002-05-31 22:47:37 +0000 |
commit | a4836ea987957f529f1418f3b1c1afe98f06361d (patch) | |
tree | e105ca8017f094e73b2ddf43f96fedaf6ef20140 | |
parent | d8840e70cc51d1c8124985cb2bd35bb27f5927a0 (diff) | |
download | gdm-a4836ea987957f529f1418f3b1c1afe98f06361d.tar.gz |
a new function (yet unused) to find out valid arguments of a command
Fri May 31 15:55:25 2002 George Lebl <jirka@5z.com>
* daemon/misc.[ch]: a new function (yet unused) to find out valid
arguments of a command
* gui/gdmXnestchooser.c: properly get the command, fixes things
so that it now really does launch the command from the
config file or the one from command line.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | daemon/misc.c | 72 | ||||
-rw-r--r-- | daemon/misc.h | 2 | ||||
-rw-r--r-- | gui/gdmXnestchooser.c | 61 |
4 files changed, 128 insertions, 16 deletions
@@ -1,3 +1,12 @@ +Fri May 31 15:55:25 2002 George Lebl <jirka@5z.com> + + * daemon/misc.[ch]: a new function (yet unused) to find out valid + arguments of a command + + * gui/gdmXnestchooser.c: properly get the command, fixes things + so that it now really does launch the command from the + config file or the one from command line. + Fri May 31 10:12:04 2002 George Lebl <jirka@5z.com> * gui/greeter/greeter_lang_list.c: add more untranslated language diff --git a/daemon/misc.c b/daemon/misc.c index 313ba733..23b45958 100644 --- a/daemon/misc.c +++ b/daemon/misc.c @@ -855,4 +855,76 @@ gdm_desetuid (void) #endif } +gboolean +gdm_test_opt (const char *cmd, const char *help, const char *option) +{ + char *q; + char *full; + char buf[1024]; + FILE *fp; + static GString *cache = NULL; + static char *cached_cmd = NULL; + gboolean got_it; + + if (cached_cmd != NULL && + strcmp (cached_cmd, cmd) == 0) { + char *p = strstr (ve_sure_string (cache->str), option); + char end; + if (p == NULL) + return FALSE; + /* must be a full word */ + end = *(p + strlen (option)); + if ((end >= 'a' && end <= 'z') || + (end >= 'A' && end <= 'Z') || + (end >= '0' && end <= '9') || + end == '_') + return FALSE; + return TRUE; + } + + g_free (cached_cmd); + cached_cmd = g_strdup (cmd); + if (cache != NULL) + g_string_assign (cache, ""); + else + cache = g_string_new (NULL); + + q = g_shell_quote (cmd); + + full = g_strdup_printf ("%s %s 2>&1", q, help); + g_free (q); + + fp = popen (full, "r"); + g_free (full); + + if (fp == NULL) + return FALSE; + + got_it = FALSE; + + while (fgets (buf, sizeof (buf), fp) != NULL) { + char *p; + char end; + + g_string_append (cache, buf); + + if (got_it) + continue; + + p = strstr (buf, option); + if (p == NULL) + continue; + /* must be a full word */ + end = *(p + strlen (option)); + if ((end >= 'a' && end <= 'z') || + (end >= 'A' && end <= 'Z') || + (end >= '0' && end <= '9') || + end == '_') + continue; + + got_it = TRUE; + } + fclose (fp); + return got_it; +} /* EOF */ diff --git a/daemon/misc.h b/daemon/misc.h index 4aef098d..a06ded6f 100644 --- a/daemon/misc.h +++ b/daemon/misc.h @@ -69,6 +69,8 @@ gboolean gdm_setup_gids (const char *login, gid_t gid); void gdm_desetuid (void); +void gdm_test_opt (const char *cmd, const char *help, const char *option); + #endif /* GDM_MISC_H */ /* EOF */ diff --git a/gui/gdmXnestchooser.c b/gui/gdmXnestchooser.c index 92e90863..e5eed828 100644 --- a/gui/gdmXnestchooser.c +++ b/gui/gdmXnestchooser.c @@ -106,6 +106,46 @@ static const struct poptOption options[] = { { NULL } }; +#if 0 +/* Perhaps this may be useful sometime */ +static gboolean +test_opt (const char *cmd, const char *help, const char *option) +{ + char *q = g_shell_quote (cmd); + char *full; + char buf[1024]; + FILE *fp; + + full = g_strdup_printf ("%s %s 2>&1", q, help); + g_free (q); + + fp = popen (full, "r"); + g_free (full); + + if (fp == NULL) + return FALSE; + + while (fgets (buf, sizeof (buf), fp) != NULL) { + char *p = strstr (buf, option); + char end; + if (p == NULL) + continue; + /* must be a full word */ + end = *(p + strlen (option)); + if ((end >= 'a' && end <= 'z') || + (end >= 'A' && end <= 'Z') || + (end >= '0' && end <= '9') || + end == '_') + continue; + + fclose (fp); + return TRUE; + } + fclose (fp); + return FALSE; +} +#endif + static char ** make_us_an_exec_vector (const char *xnest) { @@ -121,21 +161,6 @@ make_us_an_exec_vector (const char *xnest) if (ve_string_empty (xnest)) xnest = "Xnest"; - if (xnest[0] == '/' && - /* leak */ - access (ve_sure_string (ve_first_word (xnest)), X_OK) != 0) { - xnest = "Xnest"; - } - - /* leak */ - if (g_find_program_in_path (xnest) == NULL) { - xnest = "Xnest"; - /* leak */ - if (g_find_program_in_path (xnest) == NULL) { - return NULL; - } - } - xnest_vec = ve_split (xnest); if (xnest_options != NULL) options_vec = ve_split (xnest_options); @@ -285,7 +310,11 @@ main (int argc, char *argv[]) pid = fork (); if (pid == 0) { execvp (execvec[0], execvec); - g_warning ("Can't exec"); + g_warning ("Can't exec, trying Xnest"); + execvec[0] = "Xnest"; + execvp (execvec[0], execvec); + g_warning ("Can't exec that either, giving up"); + /* FIXME: this should be handled in the GUI */ _exit (1); } else if (pid < 0) { /* eeeek */ |