~lightdm-team/lightdm/1.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (C) 2010-2011 Robert Ancell.
 * Author: Robert Ancell <robert.ancell@canonical.com>
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <config.h>

#include <string.h>

#include "theme.h"

GKeyFile *
load_theme (const gchar *name, GError **error)
{
    gchar *path;
    GKeyFile *theme;
    gboolean result;

    path = g_build_filename (THEME_DIR, name, "index.theme", NULL);

    g_debug ("Looking for %s theme in %s", name, path);

    theme = g_key_file_new ();
    result = g_key_file_load_from_file (theme, path, G_KEY_FILE_NONE, error);
    g_free (path);

    if (!result)
    {
        g_key_file_free (theme);
        return NULL;
    }

    path = g_build_filename (THEME_DIR, name, NULL);
    g_key_file_set_string (theme, "_", "path", path);
    g_free (path);

    return theme;
}

gchar *
theme_get_command (GKeyFile *theme)
{
    gchar *engine, *command;

    engine = g_key_file_get_value (theme, "theme", "engine", NULL);
    if (!engine)
    {
        g_warning ("No engine defined in theme");
        return NULL;
    }

    /* FIXME: This is perhaps unsafe - 'engine' could contain a relative path, e.g. "../../../run_something_malicious".
     * Perhaps there should be a check for this or the engines need a file like /usr/share/lightdm/engines/foo.engine */
    command = g_build_filename (THEME_ENGINE_DIR, engine, NULL);
    g_free (engine);

    return command;
}