diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-22 09:29:59 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-22 09:29:59 +1000 |
commit | e395efc25f9fd60377f32c2bf1a9153d70908236 (patch) | |
tree | 8f8a4fdd19f7ab2aba423f1279b29c336a3060eb /hw/xfree86/common | |
parent | 2bb282cd45cb8149b39d72397ef5bbcfebca11d2 (diff) | |
parent | fcda98c48610fd507ca0b89c6006a5497d9dc1c9 (diff) |
Merge branch 'master' of git+ssh://git.freedesktop.org/git/xorg/xserver into multitouch
Conflicts:
configure.ac
dix/inpututils.c
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r-- | hw/xfree86/common/xf86.h | 2 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Config.c | 47 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Configure.c | 5 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Helper.c | 11 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Init.c | 78 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Priv.h | 7 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Xinput.h | 2 |
7 files changed, 104 insertions, 48 deletions
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h index f216d5e8c..b711f0555 100644 --- a/hw/xfree86/common/xf86.h +++ b/hw/xfree86/common/xf86.h @@ -232,7 +232,7 @@ extern _X_EXPORT void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y); extern _X_EXPORT void xf86SetBlackWhitePixels(ScreenPtr pScreen); extern _X_EXPORT void xf86EnableDisableFBAccess(int scrnIndex, Bool enable); extern _X_EXPORT void xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, va_list args); + const char *format, va_list args) _X_ATTRIBUTE_PRINTF(4,0); extern _X_EXPORT void xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, ...) _X_ATTRIBUTE_PRINTF(4,5); extern _X_EXPORT void xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index fef4bf1fe..f51be7e9c 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -72,8 +72,8 @@ * These paths define the way the config file search is done. The escape * sequences are documented in parser/scan.c. */ -#ifndef ROOT_CONFIGPATH -#define ROOT_CONFIGPATH "%A," "%R," \ +#ifndef ALL_CONFIGPATH +#define ALL_CONFIGPATH "%A," "%R," \ "/etc/X11/%R," "%P/etc/X11/%R," \ "%E," "%F," \ "/etc/X11/%F," "%P/etc/X11/%F," \ @@ -83,8 +83,8 @@ "%P/lib/X11/%X.%H," \ "%P/lib/X11/%X" #endif -#ifndef USER_CONFIGPATH -#define USER_CONFIGPATH "/etc/X11/%S," "%P/etc/X11/%S," \ +#ifndef RESTRICTED_CONFIGPATH +#define RESTRICTED_CONFIGPATH "/etc/X11/%S," "%P/etc/X11/%S," \ "/etc/X11/%G," "%P/etc/X11/%G," \ "/etc/X11/%X," "/etc/%X," \ "%P/etc/X11/%X.%H," \ @@ -92,14 +92,14 @@ "%P/lib/X11/%X.%H," \ "%P/lib/X11/%X" #endif -#ifndef ROOT_CONFIGDIRPATH -#define ROOT_CONFIGDIRPATH "%A," "%R," \ +#ifndef ALL_CONFIGDIRPATH +#define ALL_CONFIGDIRPATH "%A," "%R," \ "/etc/X11/%R," "%C/X11/%R," \ "/etc/X11/%X," "%C/X11/%X" #endif -#ifndef USER_CONFIGDIRPATH -#define USER_CONFIGDIRPATH "/etc/X11/%R," "%C/X11/%R," \ - "/etc/X11/%X," "%C/X11/%X" +#ifndef RESTRICTED_CONFIGDIRPATH +#define RESTRICTED_CONFIGDIRPATH "/etc/X11/%R," "%C/X11/%R," \ + "/etc/X11/%X," "%C/X11/%X" #endif #ifndef SYS_CONFIGDIRPATH #define SYS_CONFIGDIRPATH "/usr/share/X11/%X," "%D/X11/%X" @@ -552,7 +552,7 @@ xf86DriverlistFromCompile(void) * Print a READABLE ErrorMessage!!! All information that is * available is printed. */ -static void +static void _X_ATTRIBUTE_PRINTF(1,2) xf86ConfigError(const char *msg, ...) { va_list ap; @@ -2300,21 +2300,22 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) { ConfigStatus xf86HandleConfigFile(Bool autoconfig) { - char *filename, *dirname, *sysdirname; - const char *filesearch, *dirsearch; - MessageType filefrom = X_DEFAULT; - MessageType dirfrom = X_DEFAULT; char *scanptr; Bool singlecard = 0; Bool implicit_layout = FALSE; if (!autoconfig) { - if (getuid() == 0) { - filesearch = ROOT_CONFIGPATH; - dirsearch = ROOT_CONFIGDIRPATH; + char *filename, *dirname, *sysdirname; + const char *filesearch, *dirsearch; + MessageType filefrom = X_DEFAULT; + MessageType dirfrom = X_DEFAULT; + + if (!xf86PrivsElevated()) { + filesearch = ALL_CONFIGPATH; + dirsearch = ALL_CONFIGDIRPATH; } else { - filesearch = USER_CONFIGPATH; - dirsearch = USER_CONFIGDIRPATH; + filesearch = RESTRICTED_CONFIGPATH; + dirsearch = RESTRICTED_CONFIGDIRPATH; } if (xf86ConfigFile) @@ -2350,11 +2351,11 @@ xf86HandleConfigFile(Bool autoconfig) sysdirname); if (!filename && !dirname && !sysdirname) return CONFIG_NOFILE; - } - free(filename); - free(dirname); - free(sysdirname); + free(filename); + free(dirname); + free(sysdirname); + } if ((xf86configptr = xf86readConfigFile ()) == NULL) { xf86Msg(X_ERROR, "Problem parsing the config file\n"); diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 24f367ec0..994d46fc2 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -778,7 +778,8 @@ void DoShowOptions (void) { free(vlist); for (i = 0; i < xf86NumDrivers; i++) { if (xf86DriverList[i]->AvailableOptions) { - OptionInfoPtr pOption = (OptionInfoPtr)(*xf86DriverList[i]->AvailableOptions)(0,0); + const OptionInfoRec *pOption = + (*xf86DriverList[i]->AvailableOptions)(0,0); if (! pOption) { ErrorF ("(EE) Couldn't read option table for %s driver\n", xf86DriverList[i]->driverName @@ -790,7 +791,7 @@ void DoShowOptions (void) { initData = LoaderSymbol (pSymbol); if (initData) { XF86ModuleVersionInfo *vers = initData->vers; - OptionInfoPtr p; + const OptionInfoRec *p; ErrorF ("Driver[%d]:%s[%s] {\n", i,xf86DriverList[i]->driverName,vers->vendor ); diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index d99522cf6..248ccf47e 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1734,7 +1734,6 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, int format, unsigned long len, pointer value ) { RootWinPropPtr pNewProp = NULL, pRegProp; - int i; Bool existing = FALSE; DebugF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n", @@ -1775,15 +1774,11 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, DebugF("new property filled\n"); - if (NULL==xf86RegisteredPropertiesTable) { + if (xf86RegisteredPropertiesTable == NULL) { DebugF("creating xf86RegisteredPropertiesTable[] size %d\n", xf86NumScreens); - if ( NULL==(xf86RegisteredPropertiesTable=(RootWinPropPtr*)xnfcalloc(sizeof(RootWinProp),xf86NumScreens) )) { - return BadAlloc; - } - for (i=0; i<xf86NumScreens; i++) { - xf86RegisteredPropertiesTable[i] = NULL; - } + xf86RegisteredPropertiesTable = + xnfcalloc(sizeof(RootWinProp), xf86NumScreens); } DebugF("xf86RegisteredPropertiesTable %p\n", diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index c1e48eed2..5263b5f73 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -238,6 +238,65 @@ xf86PrintMarkers(void) LogPrintMarkers(); } +Bool xf86PrivsElevated(void) +{ + static Bool privsTested = FALSE; + static Bool privsElevated = TRUE; + + if (!privsTested) { +#if defined(WIN32) + privsElevated = FALSE; +#else + if ((getuid() != geteuid()) || (getgid() != getegid())) { + privsElevated = TRUE; + } else { +#if defined(HAVE_ISSETUGID) + privsElevated = issetugid(); +#elif defined(HAVE_GETRESUID) + uid_t ruid, euid, suid; + gid_t rgid, egid, sgid; + + if ((getresuid(&ruid, &euid, &suid) == 0) && + (getresgid(&rgid, &egid, &sgid) == 0)) { + privsElevated = (euid != suid) || (egid != sgid); + } + else { + printf("Failed getresuid or getresgid"); + /* Something went wrong, make defensive assumption */ + privsElevated = TRUE; + } +#else + if (getuid()==0) { + /* running as root: uid==euid==0 */ + privsElevated = FALSE; + } + else { + /* + * If there are saved ID's the process might still be privileged + * even though the above test succeeded. If issetugid() and + * getresgid() aren't available, test this by trying to set + * euid to 0. + */ + unsigned int oldeuid; + oldeuid = geteuid(); + + if (seteuid(0) != 0) { + privsElevated = FALSE; + } else { + if (seteuid(oldeuid) != 0) { + FatalError("Failed to drop privileges. Exiting\n"); + } + privsElevated = TRUE; + } + } +#endif + } +#endif + privsTested = TRUE; + } + return privsElevated; +} + static Bool xf86CreateRootWindow(WindowPtr pWin) { @@ -872,7 +931,7 @@ OsVendorInit(void) #ifdef O_NONBLOCK if (!beenHere) { - if (geteuid() == 0 && getuid() != geteuid()) + if (xf86PrivsElevated()) { int status; @@ -1043,10 +1102,11 @@ ddxProcessArgument(int argc, char **argv, int i) FatalError("Required argument to %s not specified\n", argv[i]); \ } - /* First the options that are only allowed for root */ + /* First the options that are not allowed with elevated privileges */ if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) { - if ( (geteuid() == 0) && (getuid() != 0) ) { - FatalError("The '%s' option can only be used by root.\n", argv[i]); + if (xf86PrivsElevated()) { + FatalError("The '%s' option cannot be used with " + "elevated privileges.\n", argv[i]); } else if (!strcmp(argv[i], "-modulepath")) { @@ -1074,9 +1134,9 @@ ddxProcessArgument(int argc, char **argv, int i) if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) { CHECK_FOR_REQUIRED_ARGUMENT(); - if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) { + if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { FatalError("\nInvalid argument for %s\n" - "\tFor non-root users, the file specified with %s must be\n" + "\tWith elevated privileges, the file specified with %s must be\n" "\ta relative path and must not contain any \"..\" elements.\n" "\tUsing default "__XCONFIGFILE__" search path.\n\n", argv[i], argv[i]); @@ -1087,9 +1147,9 @@ ddxProcessArgument(int argc, char **argv, int i) if (!strcmp(argv[i], "-configdir")) { CHECK_FOR_REQUIRED_ARGUMENT(); - if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) { + if (xf86PrivsElevated() && !xf86PathIsSafe(argv[i + 1])) { FatalError("\nInvalid argument for %s\n" - "\tFor non-root users, the file specified with %s must be\n" + "\tWith elevated privileges, the file specified with %s must be\n" "\ta relative path and must not contain any \"..\" elements.\n" "\tUsing default "__XCONFIGDIR__" search path.\n\n", argv[i], argv[i]); @@ -1375,7 +1435,7 @@ ddxUseMsg(void) ErrorF("\n"); ErrorF("\n"); ErrorF("Device Dependent Usage\n"); - if (getuid() == 0 || geteuid() != 0) + if (!xf86PrivsElevated()) { ErrorF("-modulepath paths specify the module search path\n"); ErrorF("-logfile file specify a log file name\n"); diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h index 8c698591e..255407b48 100644 --- a/hw/xfree86/common/xf86Priv.h +++ b/hw/xfree86/common/xf86Priv.h @@ -125,10 +125,8 @@ extern _X_EXPORT const DisplayModeRec xf86DefaultModes[]; extern _X_EXPORT const int xf86NumDefaultModes; /* xf86Configure.c */ -extern _X_EXPORT void DoConfigure(void); - -/* xf86ShowOpts.c */ -extern _X_EXPORT void DoShowOptions(void); +extern _X_EXPORT void DoConfigure(void) _X_NORETURN; +extern _X_EXPORT void DoShowOptions(void) _X_NORETURN; /* xf86Events.c */ @@ -147,6 +145,7 @@ extern _X_EXPORT Bool xf86LoadModules(char **list, pointer *optlist); extern _X_EXPORT int xf86SetVerbosity(int verb); extern _X_EXPORT int xf86SetLogVerbosity(int verb); extern _X_EXPORT Bool xf86CallDriverProbe( struct _DriverRec * drv, Bool detect_only ); +extern _X_EXPORT Bool xf86PrivsElevated(void); #endif /* _NO_XF86_PROTOTYPES */ diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index 851aeae15..ad092dd03 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -176,7 +176,7 @@ extern _X_EXPORT void xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *format, - va_list args); + va_list args) _X_ATTRIBUTE_PRINTF(4,0); /* xf86Option.c */ extern _X_EXPORT void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts); |