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 /daemon | |
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.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/misc.c | 72 | ||||
-rw-r--r-- | daemon/misc.h | 2 |
2 files changed, 74 insertions, 0 deletions
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 */ |