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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
Index: programs/luit/Imakefile
===================================================================
RCS file: /home/ncvs/xfree/xc/programs/luit/Imakefile,v
retrieving revision 1.2
retrieving revision 1.4
diff -u -u -r1.2 -r1.4
--- programs/luit/Imakefile 17 Oct 2002 01:06:09 -0000 1.2
+++ programs/luit/Imakefile 28 May 2003 16:02:35 -0000 1.4
@@ -1,19 +1,19 @@
-XCOMM $XFree86: xc/programs/luit/Imakefile,v 1.2 2002/10/17 01:06:09 dawes Exp $
+XCOMM $XFree86: xc/programs/luit/Imakefile,v 1.3tsi Exp $
#ifndef LocaleAliasFile
-#define LocaleAliasFile \
- $(XLOCALEDIR)/locale.alias
+#define LocaleAliasFile $(XLOCALEDIR)/locale.alias
#endif
+LOCALEALIASFILE = LocaleAliasFile
LOCAL_LIBRARIES = $(XFONTENCLIB)
DEPLIBS = $(DEPXFONTENCLIB)
-SYS_LIBRARIES = MathLibrary GzipLibrary
+SYS_LIBRARIES = GzipLibrary
SRCS = luit.c iso2022.c charset.c parser.c sys.c other.c
OBJS = luit.o iso2022.o charset.o parser.o sys.o other.o
-DEFINES = -DLOCALE_ALIAS_FILE=\"LocaleAliasFile\"
+DEFINES = -DLOCALE_ALIAS_FILE=\"$(LOCALEALIASFILE)\"
ComplexProgramTarget(luit)
Index: programs/luit/luit.c
===================================================================
RCS file: /home/ncvs/xfree/xc/programs/luit/luit.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -u -r1.10 -r1.11
--- programs/luit/luit.c 24 Feb 2003 01:10:25 -0000 1.10
+++ programs/luit/luit.c 8 Sep 2003 14:25:30 -0000 1.11
@@ -545,6 +545,10 @@
#endif
installHandler(SIGCHLD, sigchldHandler);
+ rc = copyTermios(0, pty);
+ if(rc < 0)
+ FatalError("Couldn't copy terminal settings\n");
+
rc = setRawTermios();
if(rc < 0)
FatalError("Couldn't set terminal to raw\n");
Index: programs/luit/luit.man
===================================================================
RCS file: /home/ncvs/xfree/xc/programs/luit/luit.man,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -u -r1.7 -r1.8
--- programs/luit/luit.man 24 Feb 2003 01:10:25 -0000 1.7
+++ programs/luit/luit.man 3 Apr 2003 16:44:36 -0000 1.8
@@ -202,8 +202,8 @@
takes no responsibility for any resulting security issues.
.B Luit
-will refuse to run if it is installed setuid and the underlying system
-does not have POSIX saved ids.
+will refuse to run if it is installed setuid and cannot safely drop
+privileges.
.SH BUGS
None of this complexity should be necessary. Stateless UTF-8
throughout the system is the way to go.
Index: programs/luit/sys.c
===================================================================
RCS file: /home/ncvs/xfree/xc/programs/luit/sys.c,v
retrieving revision 1.7
retrieving revision 1.10
diff -u -u -r1.7 -r1.10
--- programs/luit/sys.c 7 Jan 2002 20:38:30 -0000 1.7
+++ programs/luit/sys.c 8 Sep 2003 14:25:30 -0000 1.10
@@ -68,6 +68,10 @@
#include <stropts.h>
#endif
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
+#include <sys/param.h>
+#endif
+
#include "sys.h"
static int saved_tio_valid = 0;
@@ -211,6 +215,23 @@
}
int
+copyTermios(int sfd, int dfd)
+{
+ struct termios tio;
+ int rc;
+
+ rc = tcgetattr(sfd, &tio);
+ if(rc < 0)
+ return -1;
+
+ rc = tcsetattr(dfd, TCSAFLUSH, &tio);
+ if(rc < 0)
+ return -1;
+
+ return 0;
+}
+
+int
saveTermios(void)
{
int rc;
@@ -311,7 +332,8 @@
{
char name[12], *line = NULL;
int pty = -1;
- char *name1 = "pqrstuvwxyzPQRST", *name2 = "0123456789abcdef";
+ char *name1 = "pqrstuvwxyzPQRST",
+ *name2 = "0123456789abcdefghijklmnopqrstuv";
char *p1, *p2;
#ifdef HAVE_GRANTPT
@@ -363,17 +385,16 @@
pty = open(name, O_RDWR);
if(pty >= 0)
goto found;
- if(errno == ENOENT)
- goto bail;
- else
- continue;
+ /* Systems derived from 4.4BSD differ in their pty names,
+ so ENOENT doesn't necessarily imply we're done. */
+ continue;
}
}
goto bail;
found:
- line = malloc(strlen(name));
+ line = malloc(strlen(name) + 1);
strcpy(line, name);
line[5] = 't';
fix_pty_perms(line);
@@ -429,7 +450,10 @@
return -1;
}
-#ifdef _POSIX_SAVED_IDS
+/* Post-4.4 BSD systems have POSIX semantics (_POSIX_SAVED_IDS
+ or not, depending on the version). 4.3BSD and Minix do not have
+ saved IDs at all, so there's no issue. */
+#if (defined(BSD) && !defined(_POSIX_SAVED_IDS)) || defined(_MINIX)
int
droppriv()
{
@@ -438,6 +462,25 @@
if(rc < 0)
return rc;
return setgid(getgid());
+}
+#elif defined(_POSIX_SAVED_IDS)
+int
+droppriv()
+{
+ int uid = getuid();
+ int euid = geteuid();
+ int gid = getgid();
+ int egid = getegid();
+ int rc;
+
+ if((uid != euid || gid != egid) && euid != 0) {
+ errno = ENOSYS;
+ return -1;
+ }
+ rc = setuid(uid);
+ if(rc < 0)
+ return rc;
+ return setgid(gid);
}
#else
int
Index: programs/luit/sys.h
===================================================================
RCS file: /home/ncvs/xfree/xc/programs/luit/sys.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -u -r1.1 -r1.2
--- programs/luit/sys.h 2 Nov 2001 03:06:43 -0000 1.1
+++ programs/luit/sys.h 8 Sep 2003 14:25:30 -0000 1.2
@@ -24,6 +24,7 @@
int waitForInput(int fd1, int fd2);
int setWindowSize(int sfd, int dfd);
int installHandler(int signum, void (*handler)(int));
+int copyTermios(int sfd, int dfd);
int saveTermios(void);
int restoreTermios(void);
int setRawTermios(void);
|