401 lines
10 KiB
Plaintext
401 lines
10 KiB
Plaintext
$OpenBSD: patch-Wnn_uum_jhlp_c,v 1.4 2013/12/08 16:42:24 espie Exp $
|
||
--- Wnn/uum/jhlp.c.orig Sun Dec 8 16:18:39 2013
|
||
+++ Wnn/uum/jhlp.c Sun Dec 8 17:24:56 2013
|
||
@@ -80,6 +80,9 @@ struct passwd *getpwuid();
|
||
|
||
jmp_buf kk_env;
|
||
|
||
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
||
+#include <sys/param.h>
|
||
+#endif
|
||
#ifdef SYSVR2
|
||
# include <sys/param.h>
|
||
#endif /* SYSVR2 */
|
||
@@ -88,9 +91,21 @@ jmp_buf kk_env;
|
||
# include <sys/wait.h>
|
||
#endif /* HAVE_WAIT3 */
|
||
|
||
+#if defined(__OpenBSD__)
|
||
+#define USE_TERMIOS
|
||
+#else
|
||
#ifdef BSD42
|
||
+#define USE_SGTTY
|
||
+#endif
|
||
+#endif
|
||
+
|
||
+#ifdef linux
|
||
+#define USE_TERMIOS
|
||
+#endif
|
||
+
|
||
+#ifdef USE_SGTTY
|
||
# include <sgtty.h>
|
||
-#endif /* BSD42 */
|
||
+#endif
|
||
|
||
#ifdef SYSVR2
|
||
#ifdef TERMINFO
|
||
@@ -101,7 +116,7 @@ jmp_buf kk_env;
|
||
#if defined(SVR4) || defined(hpux) || defined(sgi)
|
||
#include <sys/termio.h>
|
||
#endif
|
||
-#ifdef linux
|
||
+#ifdef USE_TERMIOS
|
||
#include <termios.h>
|
||
#endif
|
||
|
||
@@ -166,14 +181,14 @@ char **argv;
|
||
flow_control = FLOW_CONTROL;
|
||
code_trans = default_code_trans;
|
||
|
||
- strcpy(username, getpwuid(getuid())->pw_name);
|
||
+ strlcpy(username, getpwuid(getuid())->pw_name, PATHNAMELEN);
|
||
if((name = getenv(WNN_USERNAME_ENV)) != NULL){
|
||
- strcpy(username, name);
|
||
+ strlcpy(username, name, PATHNAMELEN);
|
||
}
|
||
for (i = 1; i < argc;) {
|
||
if (!strcmp(argv[i++], "-L")) {
|
||
if (i >= argc || argv[i][0] == '-') default_usage();
|
||
- strcpy(lang_dir, argv[i++]);
|
||
+ strlcpy(lang_dir, argv[i++], 32);
|
||
for (;i < argc; i++) {
|
||
argv[i - 2] = argv[i];
|
||
}
|
||
@@ -185,12 +200,7 @@ char **argv;
|
||
|
||
if(*lang_dir == '\0') {
|
||
if ((p = getenv("LANG")) != NULL) {
|
||
- if (strlen(p) >= 4) {
|
||
- strncpy(lang_dir, p, 5);
|
||
- lang_dir[5] = '\0';
|
||
- } else {
|
||
- strcpy(lang_dir, p);
|
||
- }
|
||
+ strlcpy(lang_dir, p, 5);
|
||
}
|
||
}
|
||
for (f = function_db; *lang_dir && f && f->lang; f++) {
|
||
@@ -233,8 +243,8 @@ char **argv;
|
||
server_env = WNN_DEF_SERVER_ENV;
|
||
}
|
||
if(name = getenv(server_env)) {
|
||
- strcpy(def_servername, name);
|
||
- strcpy(def_reverse_servername, name);
|
||
+ strlcpy(def_servername, name, PATHNAMELEN);
|
||
+ strlcpy(def_reverse_servername, name, PATHNAMELEN);
|
||
}
|
||
}
|
||
|
||
@@ -263,9 +273,11 @@ char **argv;
|
||
|
||
|
||
#if defined(BSD42) && !defined(DGUX)
|
||
+#if !(defined(BSD) && (BSD >= 199306))
|
||
if (saveutmp() < 0) {
|
||
puts("Can't save utmp\n");
|
||
}
|
||
+#endif
|
||
#endif /* BSD42 */
|
||
|
||
|
||
@@ -312,7 +324,7 @@ char **argv;
|
||
#endif /* TERMCAP */
|
||
|
||
open_pty();
|
||
-#ifndef linux
|
||
+#if !(defined(linux) || defined(__OpenBSD__))
|
||
open_ttyp();
|
||
#endif
|
||
exec_cmd(argv);
|
||
@@ -492,7 +504,7 @@ static int do_X_opt()
|
||
|
||
static int do_k_opt()
|
||
{
|
||
- strcpy(uumkey_name_in_uumrc, optarg);
|
||
+ strlcpy(uumkey_name_in_uumrc, optarg, PATHNAMELEN);
|
||
if (*uumkey_name_in_uumrc == '\0') {
|
||
return -1;
|
||
}
|
||
@@ -502,7 +514,7 @@ static int do_k_opt()
|
||
|
||
static int do_c_opt()
|
||
{
|
||
- strcpy(convkey_name_in_uumrc, optarg);
|
||
+ strlcpy(convkey_name_in_uumrc, optarg, PATHNAMELEN);
|
||
if (*convkey_name_in_uumrc == '\0') {
|
||
return -1;
|
||
}
|
||
@@ -512,7 +524,7 @@ static int do_c_opt()
|
||
|
||
static int do_r_opt()
|
||
{
|
||
- strcpy(rkfile_name_in_uumrc, optarg);
|
||
+ strlcpy(rkfile_name_in_uumrc, optarg, PATHNAMELEN);
|
||
if (*rkfile_name_in_uumrc == '\0') {
|
||
return -1;
|
||
}
|
||
@@ -528,8 +540,8 @@ static int do_l_opt()
|
||
|
||
static int do_D_opt()
|
||
{
|
||
- strcpy(def_servername, optarg);
|
||
- strcpy(def_reverse_servername, optarg);
|
||
+ strlcpy(def_servername, optarg, PATHNAMELEN);
|
||
+ strlcpy(def_reverse_servername, optarg, PATHNAMELEN);
|
||
if (*def_servername == '\0') {
|
||
return -1;
|
||
}
|
||
@@ -538,7 +550,7 @@ static int do_D_opt()
|
||
|
||
static int do_n_opt()
|
||
{
|
||
- strcpy(username, optarg);
|
||
+ strlcpy(username, optarg, PATHNAMELEN);
|
||
if (*username == '\0') {
|
||
return -1;
|
||
}
|
||
@@ -581,14 +593,14 @@ char **argv;
|
||
#endif /* SYSVR2 */
|
||
extern char *index();
|
||
|
||
- strcpy(ostr, default_getoptstr);
|
||
- strcat(ostr, lang_db->getoptstr);
|
||
+ strlcpy(ostr, default_getoptstr, sizeof(ostr));
|
||
+ strlcat(ostr, lang_db->getoptstr, sizeof(ostr));
|
||
while ((c = getopt(argc, argv, ostr)) != EOF) {
|
||
if (!(p = index(default_ostr, c)) || (*do_opt[p - default_ostr])() < 0) {
|
||
if (!(p = index(lang_db->ostr, c)) ||
|
||
(*lang_db->do_opt[p - lang_db->ostr])() < 0) {
|
||
- strcpy(ostr, default_ostr);
|
||
- strcat(ostr, lang_db->ostr);
|
||
+ strlcpy(ostr, default_ostr, sizeof(ostr));
|
||
+ strlcat(ostr, lang_db->ostr, sizeof(ostr));
|
||
usage(ostr);
|
||
}
|
||
}
|
||
@@ -600,7 +612,7 @@ char **argv;
|
||
|
||
/** tty <20><><EFBFBD>Ф<EFBFBD><D0A4><EFBFBD> ioctl <20>Υ<EFBFBD><CEA5>å<EFBFBD> */
|
||
|
||
-#ifdef BSD42
|
||
+#ifdef USE_SGTTY
|
||
struct sgttyb savetmio;
|
||
/*
|
||
struct sgttyb ttyb =
|
||
@@ -642,11 +654,11 @@ j_term_init()
|
||
}
|
||
#endif /* BSD42 */
|
||
|
||
-#ifdef SYSVR2
|
||
+#if defined(SYSVR2) || defined(USE_TERMIOS)
|
||
#define UNDEF_STTY 0xff
|
||
|
||
-struct termio savetmio;
|
||
-struct termio terms = {
|
||
+struct termios savetmio;
|
||
+struct termios terms = {
|
||
IGNBRK | ICRNL | IXON, /* c_iflag */
|
||
ONLCR | OPOST, /* c_oflag */
|
||
B9600 | CS8 | CSTOPB | CREAD | CLOCAL, /* c_cflag */
|
||
@@ -678,13 +690,13 @@ get_rubout()
|
||
int
|
||
j_term_init()
|
||
{
|
||
- struct termio buf1;
|
||
+ struct termios buf1;
|
||
#if defined(uniosu)
|
||
struct jtermio buf2;
|
||
#endif /* defined(uniosu) */
|
||
|
||
buf1 = savetmio;
|
||
-#ifdef linux
|
||
+#ifdef USE_TERMIOS
|
||
buf1.c_lflag &= ~(ECHONL | ECHOK | ECHOE | ECHO | XCASE | ICANON | ISIG);
|
||
buf1.c_iflag = 0;
|
||
buf1.c_oflag &= ~OPOST;
|
||
@@ -705,7 +717,7 @@ j_term_init()
|
||
buf1.c_cc[VEOF] = 1; /* cf. ICANON */
|
||
buf1.c_cc[VEOL] = 0;
|
||
#endif /* linux */
|
||
- if(ioctl(ttyfd, TCSETA, &buf1) == -1){
|
||
+ if (tcsetattr(ttyfd, TCSANOW, &buf1) == -1) {
|
||
fprintf(stderr, "error in ioctl TCSETA.\n");
|
||
exit(1);
|
||
}
|
||
@@ -764,14 +776,15 @@ intfntype
|
||
chld_handler()
|
||
{
|
||
#ifdef HAVE_WAIT3
|
||
-#ifdef linux
|
||
int status;
|
||
-#else
|
||
- union wait status;
|
||
-#endif
|
||
int pid;
|
||
|
||
- if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) {
|
||
+/*
|
||
+ * Remove warning.
|
||
+ * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
|
||
+ */
|
||
+/* if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) { */
|
||
+ if ((pid = wait3((int *)&status, WNOHANG | WUNTRACED, NULL)) == child_id) {
|
||
if (WIFSTOPPED(status)) {
|
||
#ifdef SIGCONT
|
||
kill(pid, SIGCONT);
|
||
@@ -1107,7 +1120,7 @@ char **argv;
|
||
#ifdef BSD42
|
||
int pid;
|
||
#endif
|
||
-#ifdef linux
|
||
+#if defined(linux) || defined(__OpenBSD__)
|
||
struct winsize win;
|
||
extern Term_RowWidth,crow;
|
||
#endif
|
||
@@ -1140,16 +1153,18 @@ char **argv;
|
||
setpgrp(0, pid);
|
||
#endif /* BSD42 */
|
||
|
||
+#if !(defined(BSD) && (BSD >= 199306))
|
||
if (setutmp(ttypfd) == ERROR) {
|
||
puts("Can't set utmp.");
|
||
}
|
||
+#endif
|
||
|
||
-#ifdef linux
|
||
+#if defined(linux) || defined(__OpenBSD__)
|
||
setsid();
|
||
open_ttyp();
|
||
close(ptyfd);
|
||
ioctl(ttyfd, TIOCGWINSZ, &win);
|
||
- ioctl(ttypfd, TCSETA, &savetmio);
|
||
+ tcsetattr(ttypfd, TCSANOW, &savetmio);
|
||
dup2(ttypfd, 0);
|
||
dup2(ttypfd, 1);
|
||
dup2(ttypfd, 2);
|
||
@@ -1187,7 +1202,7 @@ char **argv;
|
||
err("Can't set utmp.");
|
||
}
|
||
*/
|
||
-#ifdef linux
|
||
+#if defined(linux) || defined(__OpenBSD__)
|
||
crow = win.ws_row = Term_RowWidth = win.ws_row - conv_lines;
|
||
ioctl(ttyfd, TIOCSWINSZ, &win);
|
||
setgid(getgid());
|
||
@@ -1342,7 +1357,7 @@ open_ttyp()
|
||
chown(nmbuf, getuid(), getgid());
|
||
chmod(nmbuf, 0622);
|
||
#endif /* !linux */
|
||
-#ifdef BSD42
|
||
+#ifdef USE_SGTTY
|
||
ioctl(ttyfd, TIOCGETC, &tcharsv);
|
||
ioctl(ttyfd, TIOCGLTC, <charsv);
|
||
ioctl(ttyfd, TIOCGETP, &ttyb);
|
||
@@ -1446,11 +1461,23 @@ open_ttyp()
|
||
close(open(ttyname(ttypfd), O_WRONLY, 0));
|
||
*/
|
||
#endif /* defined(SYSVR2) && !defined(linux) */
|
||
+#ifdef __OpenBSD__
|
||
+ {
|
||
+ struct winsize win;
|
||
+
|
||
+ if (ioctl(ttyfd, TIOCGWINSZ, &win) != -1) {
|
||
+ win.ws_row = crow;
|
||
+ win.ws_col = maxlength;
|
||
+ ioctl(ttypfd, TIOCSWINSZ, &win);
|
||
+ }
|
||
+ }
|
||
+#else
|
||
#ifdef TIOCSSIZE
|
||
pty_rowcol.ts_lines = crow; /* instead of lines */
|
||
pty_rowcol.ts_cols = maxlength; /* instead of columns */
|
||
ioctl(ttypfd, TIOCSSIZE, &pty_rowcol);
|
||
#endif /* TIOCSSIZE */
|
||
+#endif
|
||
}
|
||
|
||
/** pty <20>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD>ץ<EFBFBD> */
|
||
@@ -1524,15 +1551,13 @@ do_end()
|
||
signal(SIGCHLD, SIG_DFL);
|
||
fcntl(ttyfd, F_SETFL, 0);
|
||
|
||
-#ifdef BSD42
|
||
+#ifdef USE_SGTTY
|
||
ioctl(ttyfd, TIOCSETP, &savetmio);
|
||
-#endif /* BSD42 */
|
||
-#if defined(BSD43) || defined(DGUX)
|
||
ioctl(ttyfd, TIOCLSET, &local_mode_sv);
|
||
#endif /* BSD43 */
|
||
|
||
-#ifdef SYSVR2
|
||
- if(ioctl(ttyfd, TCSETA, &savetmio) < 0) {
|
||
+#ifdef USE_TERMIOS
|
||
+ if(tcsetattr(ttyfd, TCSANOW, &savetmio) < 0) {
|
||
fprintf(stderr, "error in ioctl TCSETA.\n");
|
||
exit(1);
|
||
}
|
||
@@ -1562,9 +1587,11 @@ do_end()
|
||
perror(prog);
|
||
}
|
||
|
||
+#if !(defined(BSD) && (BSD >= 199306))
|
||
if (resetutmp(ttypfd) == ERROR) {
|
||
printf("Can't reset utmp.");
|
||
}
|
||
+#endif
|
||
#ifdef TIOCSSIZE
|
||
pty_rowcol.ts_lines = 0;
|
||
pty_rowcol.ts_cols = 0;
|
||
@@ -1636,7 +1663,16 @@ ptyname(b, pty, no)
|
||
char *b, *pty;
|
||
int no;
|
||
{
|
||
+/*
|
||
+ * Change pseudo-devices.
|
||
+ * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
|
||
+ * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
|
||
+ */
|
||
+#if (defined(BSD) && (BSD >= 199306)) /* 4.4BSD-Lite by Taoka */
|
||
+ sprintf(b, "%s%1c%1c", pty, "pqrsPQRS"[(no >> 5)], ((no & 0x1f > 9)? 'a' : '0') + (no & 0x1f));
|
||
+#else /* ! 4.4BSD-Lite */
|
||
sprintf(b, "%s%1c%1x", pty, 'p' + (no >> 4), no & 0x0f);
|
||
+#endif /* ! 4.4BSD-Lite */
|
||
}
|
||
#endif /* !sgi */
|
||
|
||
@@ -1755,14 +1791,14 @@ change_size()
|
||
|
||
if ((i = win.ws_row) != 0) {
|
||
crow = Term_RowWidth = i - conv_lines;
|
||
-#ifdef linux
|
||
+#if defined(linux) || defined(__OpenBSD__)
|
||
win.ws_row = crow;
|
||
#endif
|
||
}
|
||
if ((i = win.ws_col) != 0) {
|
||
maxlength = Term_LineWidth = i;
|
||
}
|
||
-#ifdef linux
|
||
+#if defined(linux) || defined(__OpenBSD__)
|
||
ioctl(ttypfd, TIOCSWINSZ, &win);
|
||
#else /* linux */
|
||
#ifdef TIOCSSIZE
|
||
@@ -1770,7 +1806,8 @@ change_size()
|
||
pty_rowcol.ts_cols = maxlength; /* instead of columns */
|
||
ioctl(ttypfd, TIOCSSIZE, &pty_rowcol);
|
||
#endif /* TIOCSSIZE */
|
||
-#ifdef sun /* When your machine needs SIGWINCH, add your machine */
|
||
+#endif
|
||
+#if defined(sun) || defined(__OpenBSD__) /* When your machine needs SIGWINCH, add your machine */
|
||
{
|
||
int grp;
|
||
ioctl(ptyfd, TIOCGPGRP, &grp);
|
||
@@ -1781,7 +1818,6 @@ change_size()
|
||
#endif
|
||
}
|
||
#endif /* sun */
|
||
-#endif /* linux */
|
||
|
||
set_scroll_region(0, crow - 1);
|
||
if (henkan_off_flag) {
|