View | Details | Raw Unified | Return to bug 2450
Collapse All | Expand All

(-)a/configure.ac (+11 lines)
Lines 383-388 AC_CHECK_HEADERS([ \ Link Here
383
	inttypes.h \
383
	inttypes.h \
384
	limits.h \
384
	limits.h \
385
	locale.h \
385
	locale.h \
386
	iconv.h \
387
	langinfo.h \
386
	login.h \
388
	login.h \
387
	maillock.h \
389
	maillock.h \
388
	ndir.h \
390
	ndir.h \
Lines 4666-4671 AC_ARG_ENABLE([pututxline], Link Here
4666
		fi
4668
		fi
4667
	]
4669
	]
4668
)
4670
)
4671
AC_ARG_ENABLE([unicode],
4672
	[  --disable-unicode       disable use of unicode [no]],
4673
	[
4674
		if test "x$enableval" = "xno" ; then
4675
			AC_DEFINE([DISABLE_UNICODE], [1],
4676
				[Define if you don't want to use unicode])
4677
		fi
4678
	]
4679
)
4669
AC_ARG_WITH([lastlog],
4680
AC_ARG_WITH([lastlog],
4670
  [  --with-lastlog=FILE|DIR specify lastlog location [common locations]],
4681
  [  --with-lastlog=FILE|DIR specify lastlog location [common locations]],
4671
	[
4682
	[
(-)a/defines.h (+5 lines)
Lines 850-853 struct winsize { Link Here
850
# endif /* gcc version */
850
# endif /* gcc version */
851
#endif /* __predict_true */
851
#endif /* __predict_true */
852
852
853
#if defined(HAVE_LOCALE_H) && defined(HAVE_ICONV_H) && \
854
    defined(HAVE_LANGINFO_H) && !defined(DISABLE_UNICODE)
855
# define USE_UNICODE
856
#endif
857
853
#endif /* _DEFINES_H */
858
#endif /* _DEFINES_H */
(-)a/log.c (-1 / +2 lines)
Lines 443-450 do_log(LogLevel level, const char *fmt, va_list args) Link Here
443
		tmp_handler(level, fmtbuf, log_handler_ctx);
443
		tmp_handler(level, fmtbuf, log_handler_ctx);
444
		log_handler = tmp_handler;
444
		log_handler = tmp_handler;
445
	} else if (log_on_stderr) {
445
	} else if (log_on_stderr) {
446
		snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
446
		/* we want unicode multi byte characters, so do not use fmtbuf here */
447
		(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
447
		(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
448
		(void)write(log_stderr_fd, "\r\n", 2);
448
	} else {
449
	} else {
449
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
450
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
450
		openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
451
		openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
(-)a/sshkey.c (-21 / +88 lines)
Lines 44-49 Link Here
44
#include <stdio.h>
44
#include <stdio.h>
45
#include <string.h>
45
#include <string.h>
46
#include <resolv.h>
46
#include <resolv.h>
47
#ifdef USE_UNICODE
48
#include <locale.h>
49
#include <unistd.h>
50
#include <iconv.h>
51
#include <langinfo.h>
52
#endif /* USE_UNICODE */
47
#ifdef HAVE_UTIL_H
53
#ifdef HAVE_UTIL_H
48
#include <util.h>
54
#include <util.h>
49
#endif /* HAVE_UTIL_H */
55
#endif /* HAVE_UTIL_H */
Lines 1058-1074 fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len, Link Here
1058
	 * Chars to be used after each other every time the worm
1064
	 * Chars to be used after each other every time the worm
1059
	 * intersects with itself.  Matter of taste.
1065
	 * intersects with itself.  Matter of taste.
1060
	 */
1066
	 */
1067
	char    *border_ascii[] = { "+", "-", "[", "]", "+", "|", "+", "+" };
1068
	char   **border;
1061
	char	*augmentation_string = " .o+=*BOX@%&#/^SE";
1069
	char	*augmentation_string = " .o+=*BOX@%&#/^SE";
1062
	char	*retval, *p, title[FLDSIZE_X], hash[FLDSIZE_X];
1070
	char	*retval, *p, title[FLDSIZE_X - 2], hash[FLDSIZE_X - 2];
1063
	u_char	 field[FLDSIZE_X][FLDSIZE_Y];
1071
	u_char	 field[FLDSIZE_X][FLDSIZE_Y];
1064
	size_t	 i, tlen, hlen;
1072
	size_t	 i, tlen, hlen;
1065
	u_int	 b;
1073
	u_int	 b;
1066
	int	 x, y, r;
1074
	int	 x, y, r;
1067
	size_t	 len = strlen(augmentation_string) - 1;
1075
	size_t	 len = strlen(augmentation_string) - 1;
1068
1076
1069
	if ((retval = calloc((FLDSIZE_X + 3), (FLDSIZE_Y + 2))) == NULL)
1077
	if ((retval = malloc((FLDSIZE_X + 7) * FLDSIZE_Y + FLDSIZE_X * 3 * 2)) == NULL)
1070
		return NULL;
1078
		return NULL;
1071
1079
1080
#ifdef USE_UNICODE
1081
	iconv_t	 cd;
1082
	/* unicode character codes for box drawing
1083
	 * http://unicode.org/charts/PDF/U2500.pdf */
1084
	uint32_t border_unicode[] = {
1085
			0x250c, /* ┌ upper left */
1086
			0x2500, /* ─ horizontal */
1087
			0x2524, /* ┤ left of title/hash */
1088
			0x251c, /* ├ right of title/hash */
1089
			0x2510, /* ┐ upper right */
1090
			0x2502, /* │ vertical */
1091
			0x2514, /* └ lower left */
1092
			0x2518  /* ┘ lower right */ };
1093
	/* border_buffer is array of array of char
1094
	 * we use this to have statically allocated buffer */
1095
	char border_buffer[8][5];
1096
	/* border_encoded is array of pointer to char */
1097
	char *border_encoded[8];
1098
1099
	if (isatty(fileno(stdout)) == 1) {
1100
		/* initialize locale */
1101
		setlocale(LC_ALL, "");
1102
1103
#if __BYTE_ORDER == __LITTLE_ENDIAN
1104
		cd = iconv_open(nl_langinfo(CODESET), "UTF32LE");
1105
#elif __BYTE_ORDER == __BIG_ENDIAN
1106
		cd = iconv_open(nl_langinfo(CODESET), "UTF32BE");
1107
#else
1108
#error Unknown __BYTE_ORDER
1109
#endif
1110
1111
		/* encode the border elements */
1112
		for (int i = 0; i < 8; i++) {
1113
			size_t in_size = sizeof(uint32_t);;
1114
			size_t out_size = sizeof(border_buffer[i]);
1115
			char *input = (char *) &border_unicode[i];
1116
			char *output = border_buffer[i];
1117
1118
			memset(border_buffer[i], 0, out_size);
1119
			iconv(cd, &input, &in_size, &output, &out_size);
1120
1121
			/* if iconv() was successful we have a string with non-zero length
1122
			 * fall back to ascii otherwise */
1123
			if (border_buffer[i][0] != 0)
1124
				border_encoded[i] = border_buffer[i];
1125
			else
1126
				border_encoded[i] = border_ascii[i];
1127
		}
1128
1129
		iconv_close(cd);
1130
1131
		border = border_encoded;
1132
	} else
1133
#endif /* USE_UNICODE */
1134
		border = border_ascii;
1135
1072
	/* initialize field */
1136
	/* initialize field */
1073
	memset(field, 0, FLDSIZE_X * FLDSIZE_Y * sizeof(char));
1137
	memset(field, 0, FLDSIZE_X * FLDSIZE_Y * sizeof(char));
1074
	x = FLDSIZE_X / 2;
1138
	x = FLDSIZE_X / 2;
Lines 1102-1148 fingerprint_randomart(const char *alg, u_char *dgst_raw, size_t dgst_raw_len, Link Here
1102
	field[x][y] = len;
1166
	field[x][y] = len;
1103
1167
1104
	/* assemble title */
1168
	/* assemble title */
1105
	r = snprintf(title, sizeof(title), "[%s %u]",
1169
	r = snprintf(title, sizeof(title), "%s %u",
1106
		sshkey_type(k), sshkey_size(k));
1170
		sshkey_type(k), sshkey_size(k));
1107
	/* If [type size] won't fit, then try [type]; fits "[ED25519-CERT]" */
1171
	/* If "type size" won't fit, then try "type"; fits "ED25519-CERT" */
1108
	if (r < 0 || r > (int)sizeof(title))
1172
	if (r < 0 || r > (int)sizeof(title))
1109
		r = snprintf(title, sizeof(title), "[%s]", sshkey_type(k));
1173
		r = snprintf(title, sizeof(title), "%s", sshkey_type(k));
1110
	tlen = (r <= 0) ? 0 : strlen(title);
1174
	tlen = (r <= 0) ? 0 : strlen(title);
1111
1175
1112
	/* assemble hash ID. */
1176
	/* assemble hash ID. */
1113
	r = snprintf(hash, sizeof(hash), "[%s]", alg);
1177
	r = snprintf(hash, sizeof(hash), "%s", alg);
1114
	hlen = (r <= 0) ? 0 : strlen(hash);
1178
	hlen = (r <= 0) ? 0 : strlen(hash);
1115
1179
1116
	/* output upper border */
1180
	/* output upper border */
1117
	p = retval;
1181
	p = retval;
1118
	*p++ = '+';
1182
	p += sprintf(p, "%s", border[0]);
1119
	for (i = 0; i < (FLDSIZE_X - tlen) / 2; i++)
1183
	for (i = 0; i < (FLDSIZE_X - tlen - 2) / 2; i++)
1120
		*p++ = '-';
1184
		p += sprintf(p, "%s", border[1]);
1185
	p += sprintf(p, "%s", border[2]);
1121
	memcpy(p, title, tlen);
1186
	memcpy(p, title, tlen);
1122
	p += tlen;
1187
	p += tlen;
1123
	for (i += tlen; i < FLDSIZE_X; i++)
1188
	p += sprintf(p, "%s", border[3]);
1124
		*p++ = '-';
1189
	for (i += tlen + 2; i < FLDSIZE_X; i++)
1125
	*p++ = '+';
1190
		p += sprintf(p, "%s", border[1]);
1191
	p += sprintf(p, "%s", border[4]);
1126
	*p++ = '\n';
1192
	*p++ = '\n';
1127
1193
1128
	/* output content */
1194
	/* output content */
1129
	for (y = 0; y < FLDSIZE_Y; y++) {
1195
	for (y = 0; y < FLDSIZE_Y; y++) {
1130
		*p++ = '|';
1196
		p += sprintf(p, "%s", border[5]);
1131
		for (x = 0; x < FLDSIZE_X; x++)
1197
		for (x = 0; x < FLDSIZE_X; x++)
1132
			*p++ = augmentation_string[MIN(field[x][y], len)];
1198
			*p++ = augmentation_string[MIN(field[x][y], len)];
1133
		*p++ = '|';
1199
		p += sprintf(p, "%s", border[5]);
1134
		*p++ = '\n';
1200
		*p++ = '\n';
1135
	}
1201
	}
1136
1202
1137
	/* output lower border */
1203
	/* output lower border */
1138
	*p++ = '+';
1204
	p += sprintf(p, "%s", border[6]);
1139
	for (i = 0; i < (FLDSIZE_X - hlen) / 2; i++)
1205
	for (i = 0; i < (FLDSIZE_X - hlen - 2) / 2; i++)
1140
		*p++ = '-';
1206
		p += sprintf(p, "%s", border[1]);
1207
	p += sprintf(p, "%s", border[2]);
1141
	memcpy(p, hash, hlen);
1208
	memcpy(p, hash, hlen);
1142
	p += hlen;
1209
	p += hlen;
1143
	for (i += hlen; i < FLDSIZE_X; i++)
1210
	p += sprintf(p, "%s", border[3]);
1144
		*p++ = '-';
1211
	for (i += hlen + 2; i < FLDSIZE_X; i++)
1145
	*p++ = '+';
1212
		p += sprintf(p, "%s", border[1]);
1213
	p += sprintf(p, "%s", border[7]);
1146
1214
1147
	return retval;
1215
	return retval;
1148
}
1216
}
1149
- 

Return to bug 2450