Subject: Re: finger
To: None <kim@tac.nyc.ny.us>
From: T.SHIOZAKI <tshiozak@astec.co.jp>
List: tech-userlevel
Date: 09/10/2002 15:45:42
From: Kimmo Suominen <kim@tac.nyc.ny.us>
Subject: Re: finger
Date: Mon, 09 Sep 2002 23:40:58 -0400
Message-ID: <20020910034058.AAEAF7E04@beowulf.gw.com>
> Ok, I put in code to only enable 8-bit display for ISO8859-* codesets.
> Are there other single-byte 8-bit codesets?
I looked at your commit.
This is typically abuse of ISO C locale system.
I strongly oppose this code.
If we want to use 8bit codesets on finger/fingerd without any codeset
negotiation, we can only add "8bit through" option, although
not so good...
Here is a patch to add -8 option to fingerd/finger (sorry, not tested):
--- src/libexec/fingerd/fingerd.c 2002/09/10 04:06:26 1.18
+++ src/libexec/fingerd/fingerd.c 2002/09/10 06:31:19
@@ -84,7 +84,7 @@
logging = no_forward = user_required = short_list = 0;
openlog("fingerd", LOG_PID, LOG_DAEMON);
opterr = 0;
- while ((ch = getopt(argc, argv, "gsluShmpP:i")) != -1)
+ while ((ch = getopt(argc, argv, "gsluShmpP:8")) != -1)
switch (ch) {
case 'l':
logging = 1;
@@ -98,18 +98,6 @@
case 'u':
user_required = 1;
break;
- case 'i':
- /*
- * This is a hack to enable single-byte 8-bit
- * characters in the output of the default
- * finger program. The character set is not
- * communicated to the network client, and the
- * exact value does not matter much as long
- * as it enables as many 8-bit characters as
- * possible.
- */
- (void) putenv("LC_CTYPE=en_US.ISO8859-15");
- break;
case 'S':
short_list = 1;
av[ac++] = "-s";
@@ -125,6 +113,9 @@
break;
case 'g':
av[ac++] = "-g";
+ break;
+ case '8':
+ av[ac++] = "-8";
break;
case '?':
default:
--- /dev/null Tue Sep 10 09:38:40 2002
+++ src/usr.bin/finger/ascii.h Tue Sep 10 09:38:41 2002
@@ -0,0 +1,37 @@
+/* $NetBSD: $ */
+
+/*-
+ * Copyright (c)2002 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ * ASCII-dependent ctype routines.
+ */
+
+#define ascii_isspace(c) ((c)==' '||(c)=='\f'||(c)=='\n'||(c)=='r'|| \
+ (c)=='t'||(c)=='\v')
+#define ascii_isprint(c) (((c)>=0x20 && (c)<=0x7E) || ascii_isspace(c))
+#define ascii_isdigit(c) ((c)>='0' && (c)<='9')
--- src/usr.bin/finger/extern.h 2002/08/02 00:10:40 1.7
+++ src/usr.bin/finger/extern.h 2002/09/10 06:38:41
@@ -43,6 +43,7 @@
extern int oflag;
extern int gflag;
extern int pplan;
+extern int b8flag;
void enter_lastlog __P((PERSON *));
PERSON *enter_person __P((struct passwd *));
--- src/usr.bin/finger/finger.c 2002/09/10 03:02:40 1.20
+++ src/usr.bin/finger/finger.c 2002/09/10 06:38:41
@@ -87,9 +87,6 @@
#include <time.h>
#include <unistd.h>
-#include <locale.h>
-#include <langinfo.h>
-
#include "utmpentry.h"
#include "finger.h"
@@ -97,7 +94,7 @@
DB *db;
time_t now;
-int entries, gflag, lflag, mflag, oflag, sflag, pplan;
+int entries, gflag, lflag, mflag, oflag, sflag, pplan, b8flag;
char tbuf[1024];
struct utmpentry *ehead;
@@ -112,19 +109,9 @@
{
int ch;
- /* Allow user's locale settings to affect character output. */
- (void *) setlocale(LC_CTYPE, "");
-
- /*
- * Reset back to the C locale, unless we are using a known
- * single-byte 8-bit locale.
- */
- if (strncmp(nl_langinfo(CODESET), "ISO8859-", 8))
- (void *) setlocale(LC_CTYPE, "C");
-
oflag = 1; /* default to old "office" behavior */
- while ((ch = getopt(argc, argv, "lmpshog")) != -1)
+ while ((ch = getopt(argc, argv, "lmpshog8")) != -1)
switch(ch) {
case 'l':
lflag = 1; /* long format */
@@ -146,6 +133,9 @@
break;
case 'g':
gflag = 1; /* no gecos info, besides name */
+ break;
+ case '8':
+ b8flag = 1; /* 8bit through */
break;
case '?':
default:
--- src/usr.bin/finger/lprint.c 2002/09/10 03:02:40 1.17
+++ src/usr.bin/finger/lprint.c 2002/09/10 06:38:41
@@ -59,7 +59,6 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
-#include <ctype.h>
#include <string.h>
#include <paths.h>
#include <vis.h>
@@ -67,6 +66,7 @@
#include "utmpentry.h"
#include "finger.h"
#include "extern.h"
+#include "ascii.h"
#define LINE_LEN 80
#define TAB_LEN 8 /* 8 spaces between tabs */
@@ -364,11 +364,10 @@
{
char visout[5], *s2;
- if ((isprint(ch)) || (isspace(ch))) {
+ if (b8flag || ascii_isprint(ch)) {
(void)putchar(ch);
return;
}
- ch = toascii(ch);
vis(visout, ch, VIS_SAFE|VIS_NOSLASH, 0);
for (s2 = visout; *s2; s2++)
(void)putchar(*s2);
--- src/usr.bin/finger/net.c 2002/09/10 03:02:40 1.18
+++ src/usr.bin/finger/net.c 2002/09/10 06:38:41
@@ -59,7 +59,6 @@
#include <pwd.h>
#include <stdio.h>
#include <string.h>
-#include <ctype.h>
#include <unistd.h>
#include <err.h>
@@ -67,6 +66,7 @@
#include "finger.h"
#include "extern.h"
+#include "ascii.h"
void
netfinger(name)
@@ -146,9 +146,8 @@
c = '\n';
lastc = '\r';
} else {
- if (!isprint(c) && !isspace(c)) {
- c &= 0x7f;
- c |= 0x40;
+ if (b8flag && !ascii_isprint(c)) {
+ c = '?';
}
if (lastc != '\r' || c != '\n')
lastc = c;
--- src/usr.bin/finger/util.c 2002/08/02 00:10:40 1.18
+++ src/usr.bin/finger/util.c 2002/09/10 06:38:41
@@ -50,7 +50,6 @@
#include <sys/stat.h>
#include <db.h>
-#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -66,6 +65,7 @@
#include "finger.h"
#include "extern.h"
+#include "ascii.h"
static void find_idle_and_ttywrite __P((WHERE *));
static void userinfo __P((PERSON *, struct passwd *));
@@ -292,7 +292,7 @@
/* don't touch anything if the user has their own formatting */
for (p = num; *p; ++p)
- if (!isdigit((unsigned char)*p))
+ if (!ascii_isdigit((unsigned char)*p))
return(num);
len = p - num;
p = pbuf;
--
Takuya SHIOZAKI / ASTEC Products, Inc.