xserver: Branch 'master'

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Feb 10 00:32:31 UTC 2024


 hw/xfree86/parser/write.c |   38 ---------------------
 os/utils.c                |   81 ----------------------------------------------
 2 files changed, 119 deletions(-)

New commits:
commit a8bb924af19f8666a39db2cf50b0c7f00564db06
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Feb 2 18:27:57 2024 -0800

    os: Assume all supported non-WIN32 platforms have seteuid & saved_ids
    
    Removes fallback code to fork and exec a "cat" command to read files.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/xfree86/parser/write.c b/hw/xfree86/parser/write.c
index 6e96ba053..f4aa03b3d 100644
--- a/hw/xfree86/parser/write.c
+++ b/hw/xfree86/parser/write.c
@@ -65,9 +65,6 @@
 #include <sys/wait.h>
 #include <errno.h>
 
-#if defined(HAVE_SETEUID) && defined(_POSIX_SAVED_IDS) && _POSIX_SAVED_IDS > 0
-#define HAS_SAVED_IDS_AND_SETEUID
-#endif
 #if defined(WIN32)
 #define HAS_NO_UIDS
 #endif
@@ -133,38 +130,6 @@ xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr)
     int ret;
 
     if (getuid() != geteuid()) {
-
-#if !defined(HAS_SAVED_IDS_AND_SETEUID)
-        int pid, p;
-        int status;
-        void (*csig) (int);
-
-        /* Need to fork to change ruid without losing euid */
-        csig = OsSignal(SIGCHLD, SIG_DFL);
-        switch ((pid = fork())) {
-        case -1:
-            ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
-                   strerror(errno));
-            return 0;
-        case 0:                /* child */
-            if (setuid(getuid()) == -1)
-                FatalError("xf86writeConfigFile(): "
-                           "setuid failed(%s)\n", strerror(errno));
-            ret = doWriteConfigFile(filename, cptr);
-            exit(ret);
-            break;
-        default:               /* parent */
-            do {
-                p = waitpid(pid, &status, 0);
-            } while (p == -1 && errno == EINTR);
-        }
-        OsSignal(SIGCHLD, csig);
-        if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
-            return 1;           /* success */
-        else
-            return 0;
-
-#else                           /* HAS_SAVED_IDS_AND_SETEUID */
         int ruid, euid;
 
         ruid = getuid();
@@ -182,9 +147,6 @@ xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr)
                    euid, strerror(errno));
         }
         return ret;
-
-#endif                          /* HAS_SAVED_IDS_AND_SETEUID */
-
     }
     else
 #endif                          /* !HAS_NO_UIDS */
diff --git a/os/utils.c b/os/utils.c
index a4712d0bf..1620442c1 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -202,10 +202,6 @@ char *SeatId = NULL;
 
 sig_atomic_t inSignalContext = FALSE;
 
-#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
-#define HAS_SAVED_IDS_AND_SETEUID
-#endif
-
 #ifdef MONOTONIC_CLOCK
 static clockid_t clockid;
 #endif
@@ -1518,78 +1514,6 @@ void *
 Fopen(const char *file, const char *type)
 {
     FILE *iop;
-
-#ifndef HAS_SAVED_IDS_AND_SETEUID
-    struct pid *cur;
-    int pdes[2], pid;
-
-    if (file == NULL || type == NULL)
-        return NULL;
-
-    if ((*type != 'r' && *type != 'w') || type[1])
-        return NULL;
-
-    if ((cur = malloc(sizeof(struct pid))) == NULL)
-        return NULL;
-
-    if (pipe(pdes) < 0) {
-        free(cur);
-        return NULL;
-    }
-
-    switch (pid = fork()) {
-    case -1:                   /* error */
-        close(pdes[0]);
-        close(pdes[1]);
-        free(cur);
-        return NULL;
-    case 0:                    /* child */
-        if (setgid(getgid()) == -1)
-            _exit(127);
-        if (setuid(getuid()) == -1)
-            _exit(127);
-        if (*type == 'r') {
-            if (pdes[1] != 1) {
-                /* stdout */
-                dup2(pdes[1], 1);
-                close(pdes[1]);
-            }
-            close(pdes[0]);
-        }
-        else {
-            if (pdes[0] != 0) {
-                /* stdin */
-                dup2(pdes[0], 0);
-                close(pdes[0]);
-            }
-            close(pdes[1]);
-        }
-        execl("/bin/cat", "cat", file, (char *) NULL);
-        _exit(127);
-    }
-
-    /* Avoid EINTR during stdio calls */
-    OsBlockSignals();
-
-    /* parent */
-    if (*type == 'r') {
-        iop = fdopen(pdes[0], type);
-        close(pdes[1]);
-    }
-    else {
-        iop = fdopen(pdes[1], type);
-        close(pdes[0]);
-    }
-
-    cur->fp = iop;
-    cur->pid = pid;
-    cur->next = pidlist;
-    pidlist = cur;
-
-    DebugF("Fopen(%s), fp = %p\n", file, iop);
-
-    return iop;
-#else
     int ruid, euid;
 
     ruid = getuid();
@@ -1605,7 +1529,6 @@ Fopen(const char *file, const char *type)
         return NULL;
     }
     return iop;
-#endif                          /* HAS_SAVED_IDS_AND_SETEUID */
 }
 
 int
@@ -1650,11 +1573,7 @@ Pclose(void *iop)
 int
 Fclose(void *iop)
 {
-#ifdef HAS_SAVED_IDS_AND_SETEUID
     return fclose(iop);
-#else
-    return Pclose(iop);
-#endif
 }
 
 #endif                          /* !WIN32 */


More information about the xorg-commit mailing list