Hello,

I intend to apply the attached patch to allow non-US-ASCII
characters in the GECOS field (when set by chfn; usermod and useradd do
not make any verifications)

This GECOS field is a set of sub-fields:
 - name
 - room number
 - work phone
 - home phone
 - other info

Do you think allowing non-US-ASCII characters might cause issues in other
programs?

I intend to allow non-US-ASCII characters, with a warning, for the name,
room number, and other info fields.

For phone numbers, do you know if they are sometimes written using
Hindu-Arabic digits?

Best Regards,
-- 
Nekral
Index: libmisc/fields.c
===================================================================
--- libmisc/fields.c	(révision 1969)
+++ libmisc/fields.c	(copie de travail)
@@ -38,21 +38,31 @@
 /*
  * valid_field - insure that a field contains all legal characters
  *
- * The supplied field is scanned for non-printing and other illegal
- * characters.  If any illegal characters are found, valid_field
- * returns -1.  Zero is returned for success.
+ * The supplied field is scanned for non-printable and other illegal
+ * characters.
+ *  + -1 is returned if an illegal character is present.
+ *  +  1 is returned if no illegal characters are present, but the field
+ *       contains a non-printable character.
+ *  +  0 is returned otherwise.
  */
 int valid_field (const char *field, const char *illegal)
 {
 	const char *cp;
+	int err = 0;
 
-	for (cp = field;
-	     *cp && isprint (*cp & 0x7F) && !strchr (illegal, *cp); cp++);
+	for (cp = field; *cp && !strchr (illegal, *cp); cp++);
 
-	if (*cp)
-		return -1;
-	else
-		return 0;
+	if (*cp) {
+		err = -1;
+	} else {
+		for (cp = field; *cp && isprint (*cp); cp++);
+
+		if (*cp) {
+			err = 1;
+		}
+	}
+
+	return err;
 }
 
 /*
@@ -97,3 +107,4 @@
 		buf[maxsize - 1] = '\0';
 	}
 }
+
Index: src/chfn.c
===================================================================
--- src/chfn.c	(révision 1969)
+++ src/chfn.c	(copie de travail)
@@ -536,12 +536,19 @@
  */
 static void check_fields (void)
 {
-	if (valid_field (fullnm, ":,=")) {
+	int err;
+	err = valid_field (fullnm, ":,=");
+	if (err > 0) {
+		fprintf (stderr, _("%s: name with non-ASCII characters: '%s'\n"), Prog, fullnm);
+	} else if (err < 0) {
 		fprintf (stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm);
 		closelog ();
 		exit (E_NOPERM);
 	}
-	if (valid_field (roomno, ":,=")) {
+	err = valid_field (roomno, ":,=");
+	if (err > 0) {
+		fprintf (stderr, _("%s: room number with non-ASCII characters: '%s'\n"), Prog, roomno);
+	} else if (err < 0) {
 		fprintf (stderr, _("%s: invalid room number: '%s'\n"),
 		         Prog, roomno);
 		closelog ();
@@ -559,7 +566,10 @@
 		closelog ();
 		exit (E_NOPERM);
 	}
-	if (valid_field (slop, ":")) {
+	err = valid_field (slop, ":");
+	if (err > 0) {
+		fprintf (stderr, _("%s: '%s' contains non-ASCII characters\n"), Prog, slop);
+	} else if (err < 0) {
 		fprintf (stderr,
 		         _("%s: '%s' contains illegal characters\n"),
 		         Prog, slop);
Index: man/chfn.1.xml
===================================================================
--- man/chfn.1.xml	(révision 1969)
+++ man/chfn.1.xml	(copie de travail)
@@ -46,14 +46,17 @@
       GECOS field.
     </para>
 
-    <para>The only restriction placed on the contents of the fields is that
-      no control characters may be present, nor any of comma, colon, or
-      equal sign. The <emphasis remap='I'>other</emphasis> field does not
-      have this restriction, and is used to store accounting information
-      used by other applications.
+    <para>
+      These fields must not contain any colons. Except for the
+      <emphasis remap='I'>other</emphasis> field, they should not contain
+      any comma or equal sign. It is also recommended to avoid
+      non-US-ASCII characters, but this is only enforced for the phone
+      numbers. The <emphasis remap='I'>other</emphasis> field is used to
+      store accounting information used by other applications.
     </para>
 
-    <para> If none of the options are selected, <command>chfn</command>
+    <para>
+      If none of the options are selected, <command>chfn</command>
       operates in an interactive fashion, prompting the user with the
       current values for all of the fields. Enter the new value to change
       the field, or leave the line blank to use the current value. The

Reply via email to