summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--configure.ac6
-rw-r--r--log.c7
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/openbsd-compat.h3
-rw-r--r--openbsd-compat/vis.c232
-rw-r--r--openbsd-compat/vis.h91
7 files changed, 338 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 0ab9043a1..0c7bfaca0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,8 @@
8 - (djm) Fix Bug #442 for PAM case 8 - (djm) Fix Bug #442 for PAM case
9 - (djm) Bug #110: bogus error messages in lastlog_get_entry(). Fix based 9 - (djm) Bug #110: bogus error messages in lastlog_get_entry(). Fix based
10 on one by peak@argo.troja.mff.cuni.cz 10 on one by peak@argo.troja.mff.cuni.cz
11 - (djm) Bug #111: Run syslog and stderr logging through strnvis to eliminate
12 nasties. Report from peak@argo.troja.mff.cuni.cz
11 13
1220030103 1420030103
13 - (djm) Bug #461: ssh-copy-id fails with no arguments. Patch from 15 - (djm) Bug #461: ssh-copy-id fails with no arguments. Patch from
@@ -936,4 +938,4 @@
936 save auth method before monitor_reset_key_state(); bugzilla bug #284; 938 save auth method before monitor_reset_key_state(); bugzilla bug #284;
937 ok provos@ 939 ok provos@
938 940
939$Id: ChangeLog,v 1.2545 2003/01/07 05:46:58 djm Exp $ 941$Id: ChangeLog,v 1.2546 2003/01/07 06:04:18 djm Exp $
diff --git a/configure.ac b/configure.ac
index f01c0c642..d4213af5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.94 2003/01/07 04:18:33 djm Exp $ 1# $Id: configure.ac,v 1.95 2003/01/07 06:04:18 djm Exp $
2 2
3AC_INIT 3AC_INIT
4AC_CONFIG_SRCDIR([ssh.c]) 4AC_CONFIG_SRCDIR([ssh.c])
@@ -601,8 +601,8 @@ AC_CHECK_FUNCS(arc4random b64_ntop bcopy bindresvport_sa \
601 realpath recvmsg rresvport_af sendmsg setdtablesize setegid \ 601 realpath recvmsg rresvport_af sendmsg setdtablesize setegid \
602 setenv seteuid setgroups setlogin setproctitle setresgid setreuid \ 602 setenv seteuid setgroups setlogin setproctitle setresgid setreuid \
603 setrlimit setsid setpcred setvbuf sigaction sigvec snprintf \ 603 setrlimit setsid setpcred setvbuf sigaction sigvec snprintf \
604 socketpair strerror strlcat strlcpy strmode sysconf tcgetpgrp \ 604 socketpair strerror strlcat strlcpy strmode strvis sysconf \
605 truncate utimes vhangup vsnprintf waitpid __b64_ntop _getpty) 605 tcgetpgrp truncate utimes vhangup vsnprintf waitpid __b64_ntop \ _getpty)
606 606
607dnl Make sure strsep prototype is defined before defining HAVE_STRSEP 607dnl Make sure strsep prototype is defined before defining HAVE_STRSEP
608AC_CHECK_DECL(strsep, [AC_CHECK_FUNCS(strsep)]) 608AC_CHECK_DECL(strsep, [AC_CHECK_FUNCS(strsep)])
diff --git a/log.c b/log.c
index 96626d7d4..ead7e9028 100644
--- a/log.c
+++ b/log.c
@@ -386,11 +386,14 @@ do_log(LogLevel level, const char *fmt, va_list args)
386 } else { 386 } else {
387 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); 387 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
388 } 388 }
389 /* Escape magic chars in output. */
390 strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_OCTAL);
391
389 if (log_on_stderr) { 392 if (log_on_stderr) {
390 fprintf(stderr, "%s\r\n", msgbuf); 393 fprintf(stderr, "%s\r\n", fmtbuf);
391 } else { 394 } else {
392 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); 395 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
393 syslog(pri, "%.500s", msgbuf); 396 syslog(pri, "%.500s", fmtbuf);
394 closelog(); 397 closelog();
395 } 398 }
396} 399}
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 5229e7e20..8b1e5b538 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.23 2002/09/12 00:33:02 djm Exp $ 1# $Id: Makefile.in,v 1.24 2003/01/07 06:04:18 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o 19OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o 21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o
22 22
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index ae18afd34..dcb7ba15b 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.17 2002/09/12 00:33:02 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.18 2003/01/07 06:04:18 djm Exp $ */
2 2
3#ifndef _OPENBSD_H 3#ifndef _OPENBSD_H
4#define _OPENBSD_H 4#define _OPENBSD_H
@@ -26,6 +26,7 @@
26#include "glob.h" 26#include "glob.h"
27#include "readpassphrase.h" 27#include "readpassphrase.h"
28#include "getopt.h" 28#include "getopt.h"
29#include "vis.h"
29 30
30/* Home grown routines */ 31/* Home grown routines */
31#include "bsd-arc4random.h" 32#include "bsd-arc4random.h"
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c
new file mode 100644
index 000000000..303a9a5b3
--- /dev/null
+++ b/openbsd-compat/vis.c
@@ -0,0 +1,232 @@
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33#include "config.h"
34#if !defined(HAVE_STRVIS)
35
36#if defined(LIBC_SCCS) && !defined(lint)
37static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
38#endif /* LIBC_SCCS and not lint */
39
40#include <ctype.h>
41
42#include "vis.h"
43
44#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
45#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
46 isgraph((u_char)(c))) || \
47 ((flag & VIS_SP) == 0 && (c) == ' ') || \
48 ((flag & VIS_TAB) == 0 && (c) == '\t') || \
49 ((flag & VIS_NL) == 0 && (c) == '\n') || \
50 ((flag & VIS_SAFE) && \
51 ((c) == '\b' || (c) == '\007' || (c) == '\r')))
52
53/*
54 * vis - visually encode characters
55 */
56char *
57vis(dst, c, flag, nextc)
58 register char *dst;
59 int c, nextc;
60 register int flag;
61{
62 if (isvisible(c)) {
63 *dst++ = c;
64 if (c == '\\' && (flag & VIS_NOSLASH) == 0)
65 *dst++ = '\\';
66 *dst = '\0';
67 return (dst);
68 }
69
70 if (flag & VIS_CSTYLE) {
71 switch(c) {
72 case '\n':
73 *dst++ = '\\';
74 *dst++ = 'n';
75 goto done;
76 case '\r':
77 *dst++ = '\\';
78 *dst++ = 'r';
79 goto done;
80 case '\b':
81 *dst++ = '\\';
82 *dst++ = 'b';
83 goto done;
84 case '\a':
85 *dst++ = '\\';
86 *dst++ = 'a';
87 goto done;
88 case '\v':
89 *dst++ = '\\';
90 *dst++ = 'v';
91 goto done;
92 case '\t':
93 *dst++ = '\\';
94 *dst++ = 't';
95 goto done;
96 case '\f':
97 *dst++ = '\\';
98 *dst++ = 'f';
99 goto done;
100 case ' ':
101 *dst++ = '\\';
102 *dst++ = 's';
103 goto done;
104 case '\0':
105 *dst++ = '\\';
106 *dst++ = '0';
107 if (isoctal(nextc)) {
108 *dst++ = '0';
109 *dst++ = '0';
110 }
111 goto done;
112 }
113 }
114 if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
115 *dst++ = '\\';
116 *dst++ = ((u_char)c >> 6 & 07) + '0';
117 *dst++ = ((u_char)c >> 3 & 07) + '0';
118 *dst++ = ((u_char)c & 07) + '0';
119 goto done;
120 }
121 if ((flag & VIS_NOSLASH) == 0)
122 *dst++ = '\\';
123 if (c & 0200) {
124 c &= 0177;
125 *dst++ = 'M';
126 }
127 if (iscntrl(c)) {
128 *dst++ = '^';
129 if (c == 0177)
130 *dst++ = '?';
131 else
132 *dst++ = c + '@';
133 } else {
134 *dst++ = '-';
135 *dst++ = c;
136 }
137done:
138 *dst = '\0';
139 return (dst);
140}
141
142/*
143 * strvis, strnvis, strvisx - visually encode characters from src into dst
144 *
145 * Dst must be 4 times the size of src to account for possible
146 * expansion. The length of dst, not including the trailing NULL,
147 * is returned.
148 *
149 * Strnvis will write no more than siz-1 bytes (and will NULL terminate).
150 * The number of bytes needed to fully encode the string is returned.
151 *
152 * Strvisx encodes exactly len bytes from src into dst.
153 * This is useful for encoding a block of data.
154 */
155int
156strvis(dst, src, flag)
157 register char *dst;
158 register const char *src;
159 int flag;
160{
161 register char c;
162 char *start;
163
164 for (start = dst; (c = *src);)
165 dst = vis(dst, c, flag, *++src);
166 *dst = '\0';
167 return (dst - start);
168}
169
170int
171strnvis(dst, src, siz, flag)
172 register char *dst;
173 register const char *src;
174 size_t siz;
175 int flag;
176{
177 register char c;
178 char *start, *end;
179
180 for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
181 if (isvisible(c)) {
182 *dst++ = c;
183 if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
184 /* need space for the extra '\\' */
185 if (dst < end)
186 *dst++ = '\\';
187 else {
188 dst--;
189 break;
190 }
191 }
192 src++;
193 } else {
194 /* vis(3) requires up to 4 chars */
195 if (dst + 3 < end)
196 dst = vis(dst, c, flag, *++src);
197 else
198 break;
199 }
200 }
201 *dst = '\0';
202 if (dst >= end) {
203 char tbuf[5];
204
205 /* adjust return value for truncation */
206 while ((c = *src))
207 dst += vis(tbuf, c, flag, *++src) - tbuf;
208 }
209 return (dst - start);
210}
211
212int
213strvisx(dst, src, len, flag)
214 register char *dst;
215 register const char *src;
216 register size_t len;
217 int flag;
218{
219 register char c;
220 char *start;
221
222 for (start = dst; len > 1; len--) {
223 c = *src;
224 dst = vis(dst, c, flag, *++src);
225 }
226 if (len)
227 dst = vis(dst, *src, flag, '\0');
228 *dst = '\0';
229 return (dst - start);
230}
231
232#endif
diff --git a/openbsd-compat/vis.h b/openbsd-compat/vis.h
new file mode 100644
index 000000000..98924bde4
--- /dev/null
+++ b/openbsd-compat/vis.h
@@ -0,0 +1,91 @@
1/* $OpenBSD: vis.h,v 1.5 2002/02/16 21:27:17 millert Exp $ */
2/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */
3
4/*-
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)vis.h 5.9 (Berkeley) 4/3/91
37 */
38#include "config.h"
39#if !defined(HAVE_STRVIS)
40
41#ifndef _VIS_H_
42#define _VIS_H_
43
44#include <sys/types.h>
45#include <limits.h>
46
47/*
48 * to select alternate encoding format
49 */
50#define VIS_OCTAL 0x01 /* use octal \ddd format */
51#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
52
53/*
54 * to alter set of characters encoded (default is to encode all
55 * non-graphic except space, tab, and newline).
56 */
57#define VIS_SP 0x04 /* also encode space */
58#define VIS_TAB 0x08 /* also encode tab */
59#define VIS_NL 0x10 /* also encode newline */
60#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
61#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
62
63/*
64 * other
65 */
66#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
67
68/*
69 * unvis return codes
70 */
71#define UNVIS_VALID 1 /* character valid */
72#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
73#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
74#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
75#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
76
77/*
78 * unvis flags
79 */
80#define UNVIS_END 1 /* no more characters */
81
82char *vis(char *, int, int, int);
83int strvis(char *, const char *, int);
84int strnvis(char *, const char *, size_t, int);
85int strvisx(char *, const char *, size_t, int);
86int strunvis(char *, const char *);
87int unvis(char *, char, int *, int);
88
89#endif /* !_VIS_H_ */
90
91#endif /* !HAVE_STRVIS */