...
 
Commits (4)
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/charset.c,v 1.7 2003/02/24 01:10:25 dawes Exp $ */
/* $XFree86: xc/programs/luit/charset.c,v 1.8 2003/12/22 17:48:12 tsi Exp $ */
#include <stdlib.h>
#include <stdio.h>
......@@ -40,6 +40,7 @@ IdentityRecode(unsigned int n, CharsetPtr self)
return n;
}
#ifdef UNUSED
static int
IdentityReverse(unsigned int n, CharsetPtr self)
{
......@@ -66,6 +67,7 @@ IdentityReverse(unsigned int n, CharsetPtr self)
}
#undef IS_GL
}
#endif
static int
NullReverse(unsigned int n, CharsetPtr self)
......@@ -152,6 +154,8 @@ OtherCharsetRec otherCharsets[] = {
{"GBK", init_gbk, mapping_gbk, reverse_gbk, stack_gbk},
{"UTF-8", init_utf8, mapping_utf8, reverse_utf8, stack_utf8},
{"SJIS", init_sjis, mapping_sjis, reverse_sjis, stack_sjis},
{"BIG5-HKSCS", init_hkscs, mapping_hkscs, reverse_hkscs, stack_hkscs},
{"GB18030", init_gb18030, mapping_gb18030, reverse_gb18030, stack_gb18030},
{0, 0, 0, 0, 0}
};
......@@ -416,6 +420,8 @@ LocaleCharsetRec localeCharsets[] = {
{ "gbk", 0, 1, NULL, NULL, NULL, NULL, "GBK"},
{ "UTF-8", 0, 1, NULL, NULL, NULL, NULL, "UTF-8"},
{ "SJIS", 0, 1, NULL, NULL, NULL, NULL, "SJIS"},
{ "Big5-HKSCS", 0, 1, NULL, NULL, NULL, NULL, "BIG5-HKSCS"},
{ "gb18030", 0, 1, NULL, NULL, NULL, NULL, "GB18030"},
{ 0, 0, 0, 0, 0, 0, 0}
};
......
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/charset.h,v 1.4 2002/10/17 01:06:09 dawes Exp $ */
/* $XFree86: xc/programs/luit/charset.h,v 1.3 2002/07/01 02:25:59 tsi Exp $ */
#define T_FAILED 0
#define T_94 1
......
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/iso2022.c,v 1.9 2002/12/08 20:19:49 dickey Exp $ */
/* $XFree86: xc/programs/luit/iso2022.c,v 1.8 2002/10/17 01:06:09 dawes Exp $ */
#include <stdlib.h>
#include <stdio.h>
......
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/iso2022.h,v 1.5 2002/10/17 01:06:09 dawes Exp $ */
/* $XFree86: xc/programs/luit/iso2022.h,v 1.4 2002/07/01 02:25:59 tsi Exp $ */
#define ESC 0x1B
#define CSI 0x9B
......
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/luit.c,v 1.10 2003/02/24 01:10:25 dawes Exp $ */
/* $XFree86: xc/programs/luit/luit.c,v 1.9 2002/10/17 01:06:09 dawes Exp $ */
#include <stdio.h>
#include <stdlib.h>
......@@ -545,6 +545,10 @@ parent(int pid, int pty)
#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");
......
......@@ -202,8 +202,8 @@ the startup code has not been exhaustively audited, and the author
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.
......@@ -217,5 +217,8 @@ xterm(1), unicode(7), utf-8(7), charsets(7).
.I Character Code Structure and Extension Techniques (ISO\ 2022, ECMA-35).
.I Control Functions for Coded Character Sets (ISO\ 6429, ECMA-48).
.SH AUTHOR
Luit was written by Juliusz Chroboczek <jch@xfree86.org> for the
XFree86 project.
The version of
.B Luit
included in this X.org Foundataion release
was originally written by Juliusz Chroboczek <jch@freedesktop.org>
for the XFree86 Project.
......@@ -244,3 +244,182 @@ stack_sjis(unsigned char c, OtherStatePtr s)
}
}
int
init_hkscs(OtherStatePtr s)
{
s->hkscs.mapping =
FontEncMapFind("big5hkscs-0", FONT_ENCODING_UNICODE, -1, -1, NULL);
if(!s->hkscs.mapping) return 0;
s->hkscs.reverse = FontMapReverse(s->hkscs.mapping);
if(!s->hkscs.reverse) return 0;
s->hkscs.buf = -1;
return 1;
}
unsigned int
mapping_hkscs(unsigned int n, OtherStatePtr s)
{
unsigned int r;
if(n < 128) return n;
if(n == 128) return EURO_10646;
r = FontEncRecode(n, s->hkscs.mapping);
return r;
}
unsigned int
reverse_hkscs(unsigned int n, OtherStatePtr s)
{
if(n < 128) return n;
if(n == EURO_10646) return 128;
return s->hkscs.reverse->reverse(n, s->hkscs.reverse->data);
}
int
stack_hkscs(unsigned char c, OtherStatePtr s)
{
if(s->hkscs.buf < 0) {
if(c < 129) return c;
s->hkscs.buf = c;
return -1;
} else {
int b;
if(c < 0x40 || c == 0x7F) {
s->hkscs.buf = -1;
return c;
}
if(s->hkscs.buf < 0xFF && c < 0xFF)
b = (s->hkscs.buf << 8) + c;
else
b = -1;
s->hkscs.buf = -1;
return b;
}
}
/*
* Because of the 1 ~ 4 multi-bytes nature of GB18030.
* CharSet encoding is split to 2 subset (besides latin)
* The 2Bytes MB char is defined in gb18030.2000-0
* The 4Bytes MB char is defined in gb18030.2000-1
* Please note that the mapping in 2000-1 is not a 4Bytes seq => 2Bytes value
* mapping.
* To use the 2000-1 we need to 'linear' the 4Bytes sequence and 'lookup' the
* unicode value after that.
*
* For more info on GB18030 standard pls check:
* http://oss.software.ibm.com/icu/docs/papers/gb18030.html
*
* For more info on GB18030 implementation issues in XFree86 pls check:
* http://www.ibm.com/developerWorks/cn/linux/i18n/gb18030/xfree86/part1
*/
int
init_gb18030(OtherStatePtr s)
{
s->gb18030.cs0_mapping =
FontEncMapFind("gb18030.2000-0", FONT_ENCODING_UNICODE, -1, -1, NULL);
if(!s->gb18030.cs0_mapping) return 0;
s->gb18030.cs0_reverse = FontMapReverse(s->gb18030.cs0_mapping);
if(!s->gb18030.cs0_reverse) return 0;
s->gb18030.cs1_mapping =
FontEncMapFind("gb18030.2000-1", FONT_ENCODING_UNICODE, -1, -1, NULL);
if(!s->gb18030.cs1_mapping) return 0;
s->gb18030.cs1_reverse = FontMapReverse(s->gb18030.cs1_mapping);
if(!s->gb18030.cs1_reverse) return 0;
s->gb18030.linear = 0;
s->gb18030.buf_ptr = 0;
return 1;
}
unsigned int
mapping_gb18030(unsigned int n, OtherStatePtr s)
{
if(n <= 0x80) return n; /* 0x80 is valid but unassigned codepoint */
if(n >= 0xFFFF) return '?';
return FontEncRecode(n,
(s->gb18030.linear)?s->gb18030.cs1_mapping:s->gb18030.cs0_mapping);
}
unsigned int
reverse_gb18030(unsigned int n, OtherStatePtr s)
{
/* when lookup in 2000-0 failed. */
/* lookup in 2000-1 and then try to unlinear'd */
unsigned int r;
if(n <= 0x80) return n;
r = s->gb18030.cs0_reverse->reverse(n, s->gb18030.cs0_reverse->data);
if (r != 0)
return r;
r = s->gb18030.cs1_reverse->reverse(n, s->gb18030.cs1_reverse->data);
if (r != 0) {
unsigned char bytes[4];
bytes[3] = 0x30 + r % 10; r /= 10;
bytes[2] = 0x81 + r % 126; r /= 126;
bytes[1] = 0x30 + r % 10; r /= 10;
bytes[0] = 0x81 + r;
r = (unsigned int)bytes[0] << 24;
r |= (unsigned int)bytes[1] << 16;
r |= (unsigned int)bytes[2] << 8;
r |= (unsigned int)bytes[3];
}
return r;
}
int
stack_gb18030(unsigned char c, OtherStatePtr s)
{
/* if set gb18030.linear => True. the return value is "linear'd" */
if(s->gb18030.buf_ptr == 0) {
if(c <= 0x80) return c;
if (c == 0xFF) return -1;
s->gb18030.linear = 0;
s->gb18030.buf[s->gb18030.buf_ptr++] = c;
return -1;
} else if (s->gb18030.buf_ptr == 1) {
if (c >= 0x40) {
s->gb18030.buf_ptr = 0;
if ((c == 0x80) || (c == 0xFF))
return -1;
else
return (s->gb18030.buf[0] << 8) + c;
} else if (c >= 30) { /* 2Byte is (0x30 -> 0x39) */
s->gb18030.buf[s->gb18030.buf_ptr++] = c;
return -1;
} else {
s->gb18030.buf_ptr = 0;
return c;
}
} else if (s->gb18030.buf_ptr == 2) {
if ((c >= 0x81) && (c <= 0xFE)) {
s->gb18030.buf[s->gb18030.buf_ptr++] = c;
return -1;
} else {
s->gb18030.buf_ptr = 0;
return c;
}
} else {
int r = 0;
s->gb18030.buf_ptr = 0;
if ((c >= 0x30) && (c <= 0x39)) {
s->gb18030.linear = 1;
r = (((s->gb18030.buf[0] - 0x81) * 10
+ (s->gb18030.buf[1] - 0x30)) * 126
+ (s->gb18030.buf[2] - 0x81)) * 10
+ (c - 0x30);
return r;
}
return -1;
}
}
......@@ -40,10 +40,30 @@ typedef struct {
int buf;
} aux_sjis;
typedef struct {
FontMapPtr mapping;
FontMapReversePtr reverse;
int buf;
} aux_hkscs;
typedef struct {
FontMapPtr cs0_mapping; /* gb18030.2000-0 */
FontMapReversePtr cs0_reverse;
FontMapPtr cs1_mapping; /* gb18030.2000-1 */
FontMapReversePtr cs1_reverse;
int linear; /* set to '1' if stack_gb18030 linearized a 4bytes seq */
int buf[3];
int buf_ptr;
} aux_gb18030;
typedef union {
aux_gbk gbk;
aux_utf8 utf8;
aux_sjis sjis;
aux_hkscs hkscs;
aux_gb18030 gb18030;
} OtherState, *OtherStatePtr;
int init_gbk(OtherStatePtr);
......@@ -61,3 +81,13 @@ unsigned int mapping_sjis(unsigned int, OtherStatePtr);
unsigned int reverse_sjis(unsigned int, OtherStatePtr);
int stack_sjis(unsigned char, OtherStatePtr);
int init_hkscs(OtherStatePtr);
unsigned int mapping_hkscs(unsigned int, OtherStatePtr);
unsigned int reverse_hkscs(unsigned int, OtherStatePtr);
int stack_hkscs(unsigned char, OtherStatePtr);
int init_gb18030(OtherStatePtr);
unsigned int mapping_gb18030(unsigned int, OtherStatePtr);
unsigned int reverse_gb18030(unsigned int, OtherStatePtr);
int stack_gb18030(unsigned char, OtherStatePtr);
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/parser.c,v 1.2 2002/09/18 17:11:50 tsi Exp $ */
/* $XFree86$ */
#include <stdlib.h>
#include <stdio.h>
......
......@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* $XFree86: xc/programs/luit/sys.c,v 1.7 2002/01/07 20:38:30 dawes Exp $ */
/* $XFree86: xc/programs/luit/sys.c,v 1.9 2003/08/17 20:39:58 dawes Exp $ */
#include <stdlib.h>
#include <string.h>
......@@ -68,6 +68,10 @@ THE SOFTWARE.
#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;
......@@ -210,6 +214,23 @@ installHandler(int signum, void (*handler)(int))
return rc;
}
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)
{
......@@ -311,7 +332,8 @@ allocatePty(int *pty_return, char **line_return)
{
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 @@ allocatePty(int *pty_return, char **line_return)
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 @@ openTty(char *line)
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()
{
......@@ -439,6 +463,25 @@ droppriv()
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
droppriv()
......
/* $XFree86$ */
/*
Copyright (c) 2001 by Juliusz Chroboczek
......@@ -24,6 +25,7 @@ int waitForOutput(int fd);
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);
......