- fix utmp handling

- tmpnam() -> mkstemp()
--
From: Cameron Lerch <opcode@skylab.2y.net>
This commit is contained in:
brad 2000-08-12 08:31:48 +00:00
parent 65ca4f3cb8
commit 1aabea36aa
5 changed files with 243 additions and 12 deletions

View File

@ -1,19 +1,49 @@
--- src/command.c.orig Tue Nov 2 08:34:35 1999
+++ src/command.c Wed Aug 9 15:44:45 2000
@@ -680,1 +680,1 @@
--- src/command.c.orig Tue Nov 2 08:34:35 1999
+++ src/command.c Thu Aug 10 20:56:03 2000
@@ -677,7 +677,7 @@
#ifdef HAVE_SETRESGID
setresgid(my_rgid, my_rgid, my_egid);
#elif defined(HAVE_SAVED_UIDS)
- setregid(my_rgid, my_rgid);
+ setegid(my_rgid);
@@ -689,1 +689,1 @@
#else
setregid(my_egid, -1);
setregid(-1, my_rgid);
@@ -686,7 +686,7 @@
#ifdef HAVE_SETRESUID
setresuid(my_ruid, my_ruid, my_euid);
#elif defined(HAVE_SAVED_UIDS)
- setreuid(my_ruid, my_ruid);
+ seteuid(my_ruid);
@@ -709,1 +709,1 @@
#else
setreuid(my_euid, -1);
setreuid(-1, my_ruid);
@@ -706,7 +706,7 @@
#ifdef HAVE_SETRESUID
setresuid(my_ruid, my_euid, my_euid);
#elif defined(HAVE_SAVED_UIDS)
- setreuid(my_ruid, my_euid);
+ seteuid(my_euid);
@@ -718,1 +718,1 @@
#else
setreuid(-1, my_euid);
setreuid(my_ruid, -1);
@@ -715,7 +715,7 @@
#ifdef HAVE_SETRESGID
setresgid(my_rgid, my_egid, my_egid);
#elif defined(HAVE_SAVED_UIDS)
- setregid(my_rgid, my_egid);
+ setegid(my_egid);
@@ -2301,2 +2301,2 @@
#else
setregid(-1, my_egid);
setregid(my_rgid, -1);
@@ -2298,8 +2298,8 @@
because the exec*() calls reset the saved uid/gid to the
effective uid/gid -- mej */
# ifndef __CYGWIN32__
- setregid(my_rgid, my_rgid);
- setreuid(my_ruid, my_ruid);
+ setegid(my_rgid);
+ seteuid(my_ruid);
# endif /* __CYGWIN32__ */
#endif /* _HPUX_SOURCE */

View File

@ -1,5 +1,11 @@
--- src/feature.h.in.orig Wed Aug 18 16:54:24 1999
+++ src/feature.h.in Wed Aug 9 15:30:21 2000
@@ -383,1 +383,1 @@
+++ src/feature.h.in Thu Aug 10 20:56:03 2000
@@ -380,7 +380,7 @@
* may seem to be owned by root. But if you define this and don't have them,
* the utmp and tty stuff could break. Do some testing. DO NOT get this one
* wrong! */
-/* #define HAVE_SAVED_UIDS */
+#define HAVE_SAVED_UIDS
/* Use getgrnam() to determine the group id of TTY_GRP_NAME, and chgrp tty
* device files to that group. This should be ok on SVR4 and Linux systems

View File

@ -0,0 +1,105 @@
--- src/options.c.orig Tue Nov 2 08:34:35 1999
+++ src/options.c Thu Aug 10 20:42:57 2000
@@ -1328,6 +1328,10 @@
#define CTX_UNDEF ((unsigned char) -1)
#define CTX_MAX 8
+/* Template for mkstemp */
+
+#define MKSTEMP_TEMPLATE "eterm.XXXXXXXXXX"
+
/* This structure defines a context and its attributes */
struct context_struct {
@@ -1566,6 +1570,7 @@
unsigned long fsize, cnt1 = 0, cnt2 = 0;
const unsigned long max = CONFIG_BUFF - 1;
char *Command, *Output, *EnvVar, *OutFile;
+ int fd = -1;
FILE *fp;
ASSERT_RVAL(s != NULL, (char *) NULL);
@@ -1716,40 +1721,51 @@
}
ASSERT(l < CONFIG_BUFF);
Command[l] = 0;
- OutFile = tmpnam(NULL);
- if (l + strlen(OutFile) + 8 > CONFIG_BUFF) {
- print_error("Parse error in file %s, line %lu: Cannot execute command, line too long",
- file_peek_path(), file_peek_line());
- return ((char *) NULL);
- }
- strcat(Command, " >");
- strcat(Command, OutFile);
- system(Command);
- if ((fp = fopen(OutFile, "rb")) != NULL) {
- fseek(fp, 0, SEEK_END);
- fsize = ftell(fp);
- rewind(fp);
- if (fsize) {
- Output = (char *) MALLOC(fsize + 1);
- fread(Output, fsize, 1, fp);
- Output[fsize] = 0;
- fclose(fp);
- remove(OutFile);
- Output = CondenseWhitespace(Output);
- strncpy(new + j, Output, max - j);
- cnt1 = strlen(Output) - 1;
- cnt2 = max - j - 1;
- j += MIN(cnt1, cnt2);
- FREE(Output);
+ OutFile = (char *) MALLOC(sizeof(MKSTEMP_TEMPLATE) + sizeof(P_tmpdir) + 1);
+ strcpy(OutFile,P_tmpdir);
+ strcat(OutFile,MKSTEMP_TEMPLATE);
+ if ((fd = mkstemp( OutFile )) != -1)
+ {
+ if (l + strlen(OutFile) + 8 > CONFIG_BUFF) {
+ print_error("Parse error in file %s, line %lu: Cannot execute command, line too long",
+ file_peek_path(), file_peek_line());
+ return ((char *) NULL);
+ }
+ close( fd );
+ strcat(Command, " >>");
+ strcat(Command, OutFile);
+ system(Command);
+ if ((fp = fopen(OutFile, "rb")) != NULL) {
+ fseek(fp, 0, SEEK_END);
+ fsize = ftell(fp);
+ rewind(fp);
+ if (fsize) {
+ Output = (char *) MALLOC(fsize + 1);
+ fread(Output, fsize, 1, fp);
+ Output[fsize] = 0;
+ fclose(fp);
+ remove(OutFile);
+ Output = CondenseWhitespace(Output);
+ strncpy(new + j, Output, max - j);
+ cnt1 = strlen(Output) - 1;
+ cnt2 = max - j - 1;
+ j += MIN(cnt1, cnt2);
+ FREE(Output);
+ } else {
+ print_warning("Command at line %lu of file %s returned no output.", file_peek_line(), file_peek_path());
+ }
} else {
- print_warning("Command at line %lu of file %s returned no output.", file_peek_line(), file_peek_path());
+ print_warning("Output file %s could not be created. (line %lu of file %s)", NONULL(OutFile),
+ file_peek_line(), file_peek_path());
}
- } else {
- print_warning("Output file %s could not be created. (line %lu of file %s)", NONULL(OutFile),
- file_peek_line(), file_peek_path());
- }
- FREE(Command);
- } else {
+ }
+ else {
+ print_warning("Output file %s could not be opened. (line %lu of file %s)", NONULL(OutFile),
+ file_peek_line(), file_peek_path());
+ }
+ FREE(Command);
+ FREE(OutFile);
+ } else {
new[j] = *pbuff;
}
#else

View File

@ -1,12 +1,24 @@
--- src/system.c.orig Wed Oct 27 09:44:06 1999
+++ src/system.c Wed Aug 9 15:46:15 2000
@@ -70,2 +70,2 @@
+++ src/system.c Thu Aug 10 20:56:04 2000
@@ -67,8 +67,8 @@
D_OPTIONS(("system_wait(%s) called.\n", command));
if (!(pid = fork())) {
- setreuid(my_ruid, my_ruid);
- setregid(my_rgid, my_rgid);
+ seteuid(my_ruid);
+ setegid(my_rgid);
@@ -90,2 +90,2 @@
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("system_wait(): execl(%s) failed -- %s", command, strerror(errno));
exit(EXIT_FAILURE);
@@ -87,8 +87,8 @@
D_OPTIONS(("system_no_wait(%s) called.\n", command));
if (!(pid = fork())) {
- setreuid(my_ruid, my_ruid);
- setregid(my_rgid, my_rgid);
+ seteuid(my_ruid);
+ setegid(my_rgid);
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("system_no_wait(): execl(%s) failed -- %s", command, strerror(errno));
exit(EXIT_FAILURE);

View File

@ -0,0 +1,78 @@
--- src/utmp.c.orig Wed Sep 29 09:16:31 1999
+++ src/utmp.c Fri Aug 11 11:38:27 2000
@@ -68,7 +68,7 @@
#ifdef HAVE_LASTLOG_H
# include <lastlog.h>
#endif
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
# include <ttyent.h>
#endif
@@ -273,7 +273,7 @@
#else /* USE_SYSV_UTMP */
/* BSD utmp support */
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
/* used to hold the line we are using */
static char ut_line[32];
@@ -321,7 +321,7 @@
}
}
-#else /* __FreeBSD__ || NetBSD || BSDI */
+#else /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __bsdi__ */
static int utmp_pos = 0; /* position of utmp-stamp */
/*----------------------------------------------------------------------*
@@ -379,7 +379,7 @@
return rval;
}
-#endif /* __FreeBSD__ || NetBSD || BSDI */
+#endif
/*
* make a utmp entry
@@ -402,7 +402,7 @@
return;
}
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
strncpy(ut_line, pty, 31);
strncpy(utmp.ut_line, pty, UT_LINESIZE);
@@ -411,7 +411,7 @@
utmp.ut_time = time(NULL);
b_login(&utmp);
-#else /* __FreeBSD__ || NetBSD || BSDI */
+#else /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __bsdi__ */
strncpy(utmp.ut_line, ut_id, sizeof(utmp.ut_line));
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
@@ -428,10 +428,10 @@
void
cleanutent(void)
{
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
logout(ut_line);
logwtmp(ut_line, "", "");
-#else /* __FreeBSD__ */
+#else /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __bsdi__ */
FILE *fd;
privileges(INVOKE);
@@ -445,7 +445,7 @@
fclose(fd);
}
privileges(REVERT);
-#endif /* __FreeBSD__ || NetBSD || BSDI */
+#endif
}
#endif /* USE_SYSV_UTMP */