summaryrefslogtreecommitdiff
path: root/hw/xfree86/common/xf86Extensions.c
blob: d5309d558b0586b72e68aa7b2c912866ac8747c4 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright © 2011 Daniel Stone
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Author: Daniel Stone <daniel@fooishbar.org>
 */

#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif

#include "extension.h"
#include "globals.h"

#include "xf86.h"
#include "xf86Config.h"
#include "xf86Module.h"
#include "xf86Extensions.h"
#include "xf86Opt.h"
#include "optionstr.h"

#ifdef XSELINUX
#include "xselinux.h"
#endif

#ifdef XFreeXDGA
#include <X11/extensions/xf86dgaproto.h>
#endif

#ifdef XF86VIDMODE
#include <X11/extensions/xf86vmproto.h>
#include "vidmodeproc.h"
#endif

/*
 * DDX-specific extensions.
 */
static ExtensionModule extensionModules[] = {
#ifdef XF86VIDMODE
    {
	XFree86VidModeExtensionInit,
	XF86VIDMODENAME,
	&noXFree86VidModeExtension
    },
#endif
#ifdef XFreeXDGA
    {
	XFree86DGAExtensionInit,
	XF86DGANAME,
	&noXFree86DGAExtension
    },
#endif
#ifdef XF86DRI
    {
        XFree86DRIExtensionInit,
        "XFree86-DRI",
        &noXFree86DRIExtension
    },
#endif
#ifdef DRI2
    {
        DRI2ExtensionInit,
        DRI2_NAME,
        &noDRI2Extension
    }
#endif
};

static void
load_extension_config(void)
{
    XF86ConfModulePtr mod_con = xf86configptr->conf_modules;
    XF86LoadPtr modp;
    int i;

    /* Only the best. */
    if (!mod_con)
        return;

    nt_list_for_each_entry(modp, mod_con->mod_load_lst, list.next) {
        InputOption *opt;

        if (strcasecmp(modp->load_name, "extmod") != 0)
            continue;

        /* extmod options are of the form "omit <extension-name>" */
        nt_list_for_each_entry(opt, modp->load_opt, list.next) {
            const char *key = input_option_get_key(opt);
            if (strncasecmp(key, "omit", 4) != 0 || strlen(key) < 5)
                continue;
            if (EnableDisableExtension(key + 4, FALSE))
                xf86MarkOptionUsed(opt);
        }

#ifdef XSELINUX
        if ((opt = xf86FindOption(modp->load_opt,
                                  "SELinux mode disabled"))) {
            xf86MarkOptionUsed(opt);
            selinuxEnforcingState = SELINUX_MODE_DISABLED;
        }
        if ((opt = xf86FindOption(modp->load_opt,
                                  "SELinux mode permissive"))) {
            xf86MarkOptionUsed(opt);
            selinuxEnforcingState = SELINUX_MODE_PERMISSIVE;
        }
        if ((opt = xf86FindOption(modp->load_opt,
                                  "SELinux mode enforcing"))) {
            xf86MarkOptionUsed(opt);
            selinuxEnforcingState = SELINUX_MODE_ENFORCING;
        }
#endif
    }
}

void
xf86ExtensionInit(void)
{
    int i;

    load_extension_config();

    for (i = 0; i < ARRAY_SIZE(extensionModules); i++)
	LoadExtension(&extensionModules[i], TRUE);
}