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@oracle.com>
This commit is contained in:
Alan Coopersmith 2024-02-02 18:27:57 -08:00
parent b3b86ae674
commit a8bb924af1
2 changed files with 0 additions and 119 deletions

View File

@ -65,9 +65,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <errno.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) #if defined(WIN32)
#define HAS_NO_UIDS #define HAS_NO_UIDS
#endif #endif
@ -133,38 +130,6 @@ xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr)
int ret; int ret;
if (getuid() != geteuid()) { 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; int ruid, euid;
ruid = getuid(); ruid = getuid();
@ -182,9 +147,6 @@ xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr)
euid, strerror(errno)); euid, strerror(errno));
} }
return ret; return ret;
#endif /* HAS_SAVED_IDS_AND_SETEUID */
} }
else else
#endif /* !HAS_NO_UIDS */ #endif /* !HAS_NO_UIDS */

View File

@ -202,10 +202,6 @@ char *SeatId = NULL;
sig_atomic_t inSignalContext = FALSE; sig_atomic_t inSignalContext = FALSE;
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
#define HAS_SAVED_IDS_AND_SETEUID
#endif
#ifdef MONOTONIC_CLOCK #ifdef MONOTONIC_CLOCK
static clockid_t clockid; static clockid_t clockid;
#endif #endif
@ -1518,78 +1514,6 @@ void *
Fopen(const char *file, const char *type) Fopen(const char *file, const char *type)
{ {
FILE *iop; 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; int ruid, euid;
ruid = getuid(); ruid = getuid();
@ -1605,7 +1529,6 @@ Fopen(const char *file, const char *type)
return NULL; return NULL;
} }
return iop; return iop;
#endif /* HAS_SAVED_IDS_AND_SETEUID */
} }
int int
@ -1650,11 +1573,7 @@ Pclose(void *iop)
int int
Fclose(void *iop) Fclose(void *iop)
{ {
#ifdef HAS_SAVED_IDS_AND_SETEUID
return fclose(iop); return fclose(iop);
#else
return Pclose(iop);
#endif
} }
#endif /* !WIN32 */ #endif /* !WIN32 */